ref: eaa85a83fce66986a894cda17722072840a392d9
parent: 3e0c85ff63fcc55aa3874a9d64e0c6a2c45e943a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jul 3 06:45:46 EDT 2017
[cc1] Add support for union designators in emit Union is similar to struct, but in this case we only emit the last designated element.
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -337,7 +337,7 @@
emitdesig(Node *np, Type *tp)
{
Symbol *sym;
- size_t n;
+ size_t n; /* TODO: This should be SIZET */
Node *aux;
Type *p;
@@ -362,7 +362,11 @@
aux = (sym) ? *sym->u.init : convert(constnode(zero), tp, 0);
emitexp(OEXPR, aux);
break;
- /* TODO: case UNION: */
+ case UNION:
+ n = tp->n.elem-1;
+ aux = (sym) ? sym->u.init[n] : NULL;
+ emitdesig(aux, tp->p.fields[n]->type);
+ break;
case STRUCT:
case ARY:
for (n = 0; n < tp->n.elem; ++n) {