scc

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

commit 137e6e88fc39d5fffdd3423e09967f586f39887c
parent 7cf23450ad628012dfb66d72f1796955d1b34d71
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  9 Aug 2016 15:59:51 +0200

[cc1] Reemit array variables with incomplete type

These variables only can happen in the external
context, and we are emitting them with an array
of size 0, which is not ever emitted, so the
solution is to emit it twice and let to the backend
to handle the situation.

Diffstat:
Mcc1/decl.c | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -710,6 +710,19 @@ redcl(Symbol *sym, Type *tp, Symbol **pars, int sclass) break; } sym->flags = flags; + if (tp->op == ARY && + !(sym->type->prop&TDEFINED) && + tp->prop&TDEFINED) { + /* + * The symbol was already emitted, but in case of being an + * array it was emitted with an incorrect type, so the most + * simple solution is to emit twice the symbol, and let to + * the second declaration to have the correct type. + */ + sym->type = tp; + sym->flags &= ~SEMITTED; + emit(ODECL, sym); + } return sym;