Fix crash with anonymous function parameters in function definitions.
Issue #135.
This commit is contained in:
54
decl.cpp
54
decl.cpp
@@ -261,10 +261,7 @@ Declarator::GetFunctionInfo(DeclSpecs *ds, std::vector<Symbol *> *funArgs) {
|
|||||||
Assert(d != NULL);
|
Assert(d != NULL);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < d->functionParams.size(); ++i) {
|
for (unsigned int i = 0; i < d->functionParams.size(); ++i) {
|
||||||
Declaration *pdecl = d->functionParams[i];
|
Symbol *sym = d->GetSymbolForFunctionParameter(i);
|
||||||
Assert(pdecl->declarators.size() == 1);
|
|
||||||
|
|
||||||
Symbol *sym = pdecl->declarators[0]->GetSymbol();
|
|
||||||
sym->type = sym->type->ResolveUnboundVariability(Type::Varying);
|
sym->type = sym->type->ResolveUnboundVariability(Type::Varying);
|
||||||
funArgs->push_back(sym);
|
funArgs->push_back(sym);
|
||||||
}
|
}
|
||||||
@@ -353,25 +350,7 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const {
|
|||||||
for (unsigned int i = 0; i < functionParams.size(); ++i) {
|
for (unsigned int i = 0; i < functionParams.size(); ++i) {
|
||||||
Declaration *d = functionParams[i];
|
Declaration *d = functionParams[i];
|
||||||
|
|
||||||
char buf[32];
|
Symbol *sym = GetSymbolForFunctionParameter(i);
|
||||||
Symbol *sym;
|
|
||||||
if (d->declarators.size() == 0) {
|
|
||||||
// function declaration like foo(float), w/o a name for
|
|
||||||
// the parameter
|
|
||||||
sprintf(buf, "__anon_parameter_%d", i);
|
|
||||||
sym = new Symbol(buf, pos);
|
|
||||||
sym->type = d->declSpecs->GetBaseType(pos);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sym = d->declarators[0]->GetSymbol();
|
|
||||||
if (sym == NULL) {
|
|
||||||
// Handle more complex anonymous declarations like
|
|
||||||
// float (float **).
|
|
||||||
sprintf(buf, "__anon_parameter_%d", i);
|
|
||||||
sym = new Symbol(buf, d->declarators[0]->pos);
|
|
||||||
sym->type = d->declarators[0]->GetType(d->declSpecs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->declSpecs->storageClass != SC_NONE)
|
if (d->declSpecs->storageClass != SC_NONE)
|
||||||
Error(sym->pos, "Storage class \"%s\" is illegal in "
|
Error(sym->pos, "Storage class \"%s\" is illegal in "
|
||||||
@@ -499,6 +478,35 @@ Declarator::GetType(DeclSpecs *ds) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Symbol *
|
||||||
|
Declarator::GetSymbolForFunctionParameter(int paramNum) const {
|
||||||
|
Assert(paramNum < (int)functionParams.size());
|
||||||
|
Declaration *d = functionParams[paramNum];
|
||||||
|
|
||||||
|
char buf[32];
|
||||||
|
Symbol *sym;
|
||||||
|
if (d->declarators.size() == 0) {
|
||||||
|
// function declaration like foo(float), w/o a name for
|
||||||
|
// the parameter
|
||||||
|
sprintf(buf, "__anon_parameter_%d", paramNum);
|
||||||
|
sym = new Symbol(buf, pos);
|
||||||
|
sym->type = d->declSpecs->GetBaseType(pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Assert(d->declarators.size() == 1);
|
||||||
|
sym = d->declarators[0]->GetSymbol();
|
||||||
|
if (sym == NULL) {
|
||||||
|
// Handle more complex anonymous declarations like
|
||||||
|
// float (float **).
|
||||||
|
sprintf(buf, "__anon_parameter_%d", paramNum);
|
||||||
|
sym = new Symbol(buf, d->declarators[0]->pos);
|
||||||
|
sym->type = d->declarators[0]->GetType(d->declSpecs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Declaration
|
// Declaration
|
||||||
|
|
||||||
|
|||||||
2
decl.h
2
decl.h
@@ -153,6 +153,8 @@ public:
|
|||||||
declarator and symbols for its arguments in *args. */
|
declarator and symbols for its arguments in *args. */
|
||||||
Symbol *GetFunctionInfo(DeclSpecs *ds, std::vector<Symbol *> *args);
|
Symbol *GetFunctionInfo(DeclSpecs *ds, std::vector<Symbol *> *args);
|
||||||
|
|
||||||
|
Symbol *GetSymbolForFunctionParameter(int paramNum) const;
|
||||||
|
|
||||||
/** Returns the symbol associated with the declarator. */
|
/** Returns the symbol associated with the declarator. */
|
||||||
Symbol *GetSymbol() const;
|
Symbol *GetSymbol() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user