From 87f8893886570364ce18776490f470232860772e Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 9 Dec 2023 17:33:46 +0800 Subject: [PATCH 1/2] Avoided "Variable 'XXX' is defined but never used" error message resulted from an earlier error. --- src/cc65/symtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index a4ca9e23d..86a92a019 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -178,7 +178,7 @@ static void CheckSymTable (SymTable* Tab) if (IS_Get (&WarnUnusedFunc)) { Warning ("Function '%s' is defined but never used", Entry->Name); } - } else { + } else if (!IsAnonName (Entry->Name)) { if (IS_Get (&WarnUnusedVar)) { Warning ("Variable '%s' is defined but never used", Entry->Name); } From d8a722b63826ea4a1df2bb7a7f4e1197f7707117 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 9 Dec 2023 17:34:01 +0800 Subject: [PATCH 2/2] Improved diagnostics on multiple definition of struct/union types. --- src/cc65/declare.c | 10 ---------- src/cc65/symtab.c | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index b6620785f..96e1f1074 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1220,11 +1220,6 @@ NextMember: if (CurTok.Tok != TOK_COMMA) { Flags |= SC_FICTITIOUS; } - /* Empty union is not supported now */ - if (UnionSize == 0) { - Error ("Empty union type '%s' is not supported", Name); - } - /* Make a real entry from the forward decl and return it */ return AddStructSym (Name, SC_UNION | SC_DEF | Flags, UnionSize, FieldTab, DSFlags); } @@ -1471,11 +1466,6 @@ NextMember: if (CurTok.Tok != TOK_COMMA) { Flags |= SC_FICTITIOUS; } - /* Empty struct is not supported now */ - if (StructSize == 0) { - Error ("Empty struct type '%s' is not supported", Name); - } - /* Make a real entry from the forward decl and return it */ return AddStructSym (Name, SC_STRUCT | SC_DEF | Flags, StructSize, FieldTab, DSFlags); } diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 86a92a019..1b5c1e0b5 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -919,14 +919,8 @@ SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTabl /* SCType must be struct or union */ PRECONDITION (SCType == SC_STRUCT || SCType == SC_UNION); - if ((Flags & SC_FICTITIOUS) == 0) { - /* Do we have an entry with this name already? */ - TagEntry = FindSymInTable (CurTagTab, Name, HashStr (Name)); - } else { - /* Add a fictitious symbol in the fail-safe table */ - TagEntry = 0; - CurTagTab = FailSafeTab; - } + /* Do we have an entry with this name already? */ + TagEntry = FindSymInTable (CurTagTab, Name, HashStr (Name)); if (TagEntry) { @@ -954,6 +948,15 @@ SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTabl if (DSFlags != 0) { *DSFlags |= DS_NEW_TYPE_DEF; } + + if ((Flags & SC_FICTITIOUS) == SC_FICTITIOUS) { + /* Add a fictitious symbol in the fail-safe table */ + TagEntry = 0; + } else if (Size == 0) { + /* Empty struct is not supported now */ + Error ("Empty %s type '%s' is not supported", SCType == SC_STRUCT ? "struct" : "union", Name); + TagEntry = 0; + } } }