scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit ee4660c4b1081fbe4d5ae68a68132f9e1b629a5c
parent 245fc40cffc3b201f5cdf9e1b485fc7fa06e1463
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 19 Jan 2016 10:49:29 +0100

Do not emit decalrations until initializer

Incomplete array types are converted to complete when they
have a initializer, but incomplete types are not emited, so
it is impossible for the backend to know what is the size of
the initializer.

Diffstat:
cc1/decl.c | 4++--
cc1/init.c | 1+
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -789,12 +789,12 @@ identifier(struct decl *dcl) sym->flags = flags; } - if (sym->token == IDEN && sym->type->op != FTN) - emit(ODECL, sym); if (accept('=')) initializer(sym, sym->type); if (!(sym->flags & (ISGLOBAL|ISEXTERN)) && tp->op != FTN) sym->flags |= ISDEFINED; + if (sym->token == IDEN && sym->type->op != FTN) + emit(ODECL, sym); return sym; } diff --git a/cc1/init.c b/cc1/init.c @@ -244,6 +244,7 @@ initializer(Symbol *sym, Type *tp) errorp("function '%s' is initialized like a variable", sym->name); np = initialize(tp); + emit(ODECL, sym); if (flags & ISDEFINED) { errorp("redeclaration of '%s'", sym->name); } else if ((flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) != 0) {