ref: 975c7b569ff06c32eafd382884e8d583b5674679
parent: bc1d0b048c6c8de00d0b6362ce9a1a624f35349d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jul 13 15:55:17 EDT 2017
[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
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -364,8 +364,8 @@
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:
--- a/cc1/init.c
+++ b/cc1/init.c
@@ -322,11 +322,8 @@
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:
--
⑨