scc

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

commit a06a212f80e6aa82aa335516bc5b4cbe17022625
parent 830e83ac3127699ad53a85f0e4d868040ca38580
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 13 Jul 2017 19:55:17 +0200

[cc1] Fix initialization of unions

Unions were handled in the same way than structs but they are very
different things, and in this case we only have to store a value
in the initializer, but we were storing all of them and using the
value of the last field in the union

Diffstat:
cc1/code.c | 4++--
cc1/init.c | 7++-----
2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -364,8 +364,8 @@ emitdesig(Node *np, Type *tp) break; case UNION: n = tp->n.elem-1; - aux = (sym) ? sym->u.init[n] : NULL; - emitdesig(aux, tp->p.fields[n]->type); + aux = (sym) ? sym->u.init[0] : NULL; + emitdesig(aux, aux->type); break; case STRUCT: case ARY: diff --git a/cc1/init.c b/cc1/init.c @@ -322,11 +322,8 @@ autoinit(Symbol *sym, Node *np) repeat: switch (tp->op) { case UNION: - if (!(np->flags & NCONST)) - abort(); /* TODO */ - n = tp->n.elem-1; - tp = tp->p.fields[n]->type; - np = np->sym->u.init[n]; + np = np->sym->u.init[0]; + tp = np->type; goto repeat; case ARY: case STRUCT: