scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e74b4c840eed17236373664d1fcf773a434e5f6b
parent eda760b338438afdf9f20d30be45b04042daa74e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Jul 2014 14:58:06 +0200

Detect bad class specifiers in function declarations

function declarations in non external context could be specified
with a class storage, but a good compiler should detect this
situation and gives and error this problem.

Diffstat:
Mcc1/decl.c | 34++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -397,7 +397,7 @@ decl(void) { Type *tp; Symbol *sym; - int8_t sclass; + int8_t sclass, isfun; tp = specifier(&sclass); if (accept(';')) @@ -406,12 +406,30 @@ decl(void) do { sym = declarator(tp, ID_EXPECTED); sym->s.isdefined = 1; + isfun = BTYPE(sym->type) != FTN; + switch (sclass) { - case REGISTER: sym->s.isregister = 1; break; - case STATIC: sym->s.isstatic = 1; break; - case EXTERN: sym->s.isdefined = 0; break; - case TYPEDEF: /* TODO: */;break; - case AUTO: default: sym->s.isauto = 1; + case TYPEDEF: + /* TODO: */ + break; + case STATIC: + sym->s.isstatic = 1; + break; + case EXTERN: + sym->s.isdefined = 0; + break; + case REGISTER: + sym->s.isregister = 1; + if (isfun) + goto bad_function; + break; + case AUTO: + if (isfun) + goto bad_function; + /* passtrough */ + default: + sym->s.isauto = 1; + break; } if (accept('=')) initializer(sym); @@ -419,6 +437,10 @@ decl(void) } while (accept(',')); expect(';'); + return; + +bad_function: + error("invalid storage class for function '%s'", sym->name); } Type *