Fixed assertion failure when there is an undefined symbol used in a parameter list.

This commit is contained in:
acqn 2023-11-27 20:42:50 +08:00
parent ab0ab8e36f
commit 546be1d5dd
3 changed files with 14 additions and 2 deletions

View File

@ -1850,6 +1850,7 @@ static FuncDesc* ParseFuncDecl (void)
}
/* Parse params */
PushLexicalLevel (LEX_LEVEL_PARAM_LIST);
if ((F->Flags & FD_OLDSTYLE) == 0) {
/* New-style function */
ParseAnsiParamList (F);
@ -1857,6 +1858,7 @@ static FuncDesc* ParseFuncDecl (void)
/* Old-style function */
ParseOldStyleParamList (F);
}
PopLexicalLevel ();
/* Remember the last function parameter. We need it later for several
** purposes, for example when passing stuff to fastcall functions. Since

View File

@ -1221,7 +1221,14 @@ SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs
ident Ident;
/* Do we have an entry with this name already? */
SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name));
SymEntry* Entry;
/* HACK: only allows to add parameter symbols in a parameter list */
if ((Flags & SC_PARAM) == 0 && GetLexicalLevel () == LEX_LEVEL_PARAM_LIST) {
return 0;
}
Entry = FindSymInTable (Tab, Name, HashStr (Name));
if (Entry) {
int CheckExtern = 0;
@ -1419,7 +1426,9 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags)
/* Add an alias of the global symbol to the local symbol table */
if (Tab == SymTab0 && SymTab != SymTab0 && Entry->Owner != SymTab && Alias == 0) {
Alias = AddLocalSym (Name, T, SC_ALIAS, 0);
Alias->V.A.Field = Entry;
if (Alias != 0) {
Alias->V.A.Field = Entry;
}
}
/* Return the entry */

View File

@ -78,6 +78,7 @@ struct LexicalLevel {
#define LEX_LEVEL_FUNCTION 2U
#define LEX_LEVEL_BLOCK 3U
#define LEX_LEVEL_STRUCT 4U
#define LEX_LEVEL_PARAM_LIST 5U /* HACK for error recovery */
/* Forwards */
struct FuncDesc;