From d68cd90e47bfe96a5b85bd57328a25687a59f016 Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 6 Aug 2020 17:22:19 +0800 Subject: [PATCH] Function declaration in functions cannot have storage classes other than 'extern'. --- src/cc65/locals.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 03bc80f21..6b4c13fce 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -426,13 +426,25 @@ static void ParseOneDecl (const DeclSpec* Spec) /* Read the declaration */ ParseDecl (Spec, &Decl, DM_NEED_IDENT); - /* Set the correct storage class for functions */ + /* Check if there are any non-extern storage classes set for function + ** declarations. The only valid storage class for function declarations + ** inside functions is 'extern'. + */ if ((Decl.StorageClass & SC_FUNC) == SC_FUNC) { - /* Function prototypes are always external */ - if ((Decl.StorageClass & SC_EXTERN) == 0) { - Warning ("Function must be extern"); + + /* Check if there are explicitly specified non-external storage classes */ + if ((Spec->Flags & DS_DEF_STORAGE) != DS_DEF_STORAGE && + (Decl.StorageClass & SC_EXTERN) == 0 && + (Decl.StorageClass & SC_STORAGEMASK) != 0) { + Error ("Illegal storage class on function"); } + + /* The default storage class could be wrong. Just use 'extern' in all + ** cases. + */ + Decl.StorageClass &= ~SC_STORAGEMASK; Decl.StorageClass |= SC_EXTERN; + } /* If we don't have a name, this was flagged as an error earlier.