Skip to content

Commit

Permalink
Merge pull request cc65#2271 from acqn/InternalFix
Browse files Browse the repository at this point in the history
[cc65] Fixed assertion failure when there is an undeclared symbol used in a parameter list
  • Loading branch information
mrdudz authored Nov 28, 2023
2 parents 97cfb8c + 546be1d commit 2af16ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cc65/declare.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,13 +1902,15 @@ static FuncDesc* ParseFuncDecl (void)
}

/* Parse params */
PushLexicalLevel (LEX_LEVEL_PARAM_LIST);
if ((F->Flags & FD_OLDSTYLE) == 0) {
/* New-style function */
ParseAnsiParamList (F);
} else {
/* 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
Expand Down
13 changes: 11 additions & 2 deletions src/cc65/symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/cc65/symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2af16ee

Please sign in to comment.