From 3fbefdef451de5a72d2cbf4f86a00d1e6896f8b1 Mon Sep 17 00:00:00 2001 From: acqn Date: Fri, 19 Aug 2022 18:48:52 +0800 Subject: [PATCH] Fixed warning on forward declaration of enums. Fixed the issue that global static variables put on zeropage were missing optimization. --- src/cc65/compile.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cc65/compile.c b/src/cc65/compile.c index d1f78098d..7f2cd8ba0 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -207,7 +207,7 @@ static void Parse (void) /* Allow initialization */ if (CurTok.Tok == TOK_ASSIGN) { - /* This is a definition */ + /* This is a definition with storage */ if (SymIsDef (Entry)) { Error ("Global variable '%s' has already been defined", Entry->Name); @@ -251,6 +251,7 @@ static void Parse (void) ParseInit (Entry->Type); } else { + /* This is a declaration */ if (IsTypeVoid (Decl.Type)) { /* We cannot declare variables of type void */ Error ("Illegal type for variable '%s'", Decl.Ident); @@ -261,6 +262,15 @@ static void Parse (void) Error ("Variable '%s' has unknown size", Decl.Ident); } } else { + /* Check for enum forward declaration. + ** Warn about it when extensions are not allowed. + */ + if (Size == 0 && IsTypeEnum (Decl.Type)) { + if (IS_Get (&Standard) != STD_CC65) { + Warning ("ISO C forbids forward references to 'enum' types"); + } + } + /* A global (including static) uninitialized variable is ** only a tentative definition. For example, this is valid: ** int i; @@ -287,17 +297,9 @@ static void Parse (void) } /* Make the symbol zeropage according to the segment address size */ - if ((Entry->Flags & SC_EXTERN) != 0) { + if ((Entry->Flags & SC_STATIC) != 0) { if (GetSegAddrSize (GetSegName (CS->CurDSeg)) == ADDR_SIZE_ZP) { Entry->Flags |= SC_ZEROPAGE; - /* Check for enum forward declaration. - ** Warn about it when extensions are not allowed. - */ - if (Size == 0 && IsTypeEnum (Decl.Type)) { - if (IS_Get (&Standard) != STD_CC65) { - Warning ("ISO C forbids forward references to 'enum' types"); - } - } } }