scc

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

commit 60593515d461f8665b59f7c51eca7556fff69256
parent b0ffc63f8087baa7e5c77911b7b6fb14c49ec306
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Jul 2014 13:49:48 +0200

Check storage class in initializer

Only defined elements can be be initialized. I am not sure if is an
error initialize an extern symbol, or it is only a warning. I
suspect it should be an error, but gcc only emits a warning.

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

diff --git a/cc1/decl.c b/cc1/decl.c @@ -240,12 +240,18 @@ invalid_type: error("invalid type specification"); } -/* TODO: check storage class and correctness of the initializator */ +/* TODO: check correctness of the initializator */ +/* TODO: emit initializer */ static struct node * -initializer(register Type *tp) +initializer(Symbol *sym) { + register Type *tp = sym->type; + + if (!sym->s.isdefined) + error("'%s' initialized and declared extern", sym->name); + if (accept('{')) { - initializer(tp); + initializer(sym); expect('}'); } else { do { @@ -375,7 +381,7 @@ enumdcl(void) sym = newiden(); sym->type = inttype; if (accept('=')) - initializer(inttype); + initializer(sym); sym->u.i = val++; newfield(tp, sym); if (!accept(',')) @@ -405,7 +411,7 @@ decl(void) case AUTO: default: sym->s.isauto = 1; } if (accept('=')) - initializer(sym->type); /* TODO: emit initializer */ + initializer(sym); emitdcl(sym); } while (accept(',')); } @@ -453,7 +459,7 @@ extdecl(void) if (BTYPE(tp) != FTN) { if (accept('=')) - initializer(tp); + initializer(sym); emitdcl(sym); } else if (yytoken == '{') { curfun = sym;