commit dd69378b91c35a62d9e2960fbad9ae11e4a06ec4
parent 113195c2eace9d4fedf6e1a14cd9b6946b51d65d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 27 Sep 2016 17:04:49 +0200
[cc1] Fix definition of union types
The size of unions was always wrong (and 0). This patch
also fixes the offset of fields in unions, which must
be 0 always.
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/cc1/types.c b/cc1/types.c
@@ -176,7 +176,7 @@ typesize(Type *tp)
{
Symbol **sp;
Type *aux;
- unsigned long size;
+ unsigned long size, offset;
int align, a;
TINT n;
@@ -200,10 +200,10 @@ typesize(Type *tp)
* field, and the size of a struct is the sum
* of the size of every field plus padding bits.
*/
- align = size = 0;
+ offset = align = size = 0;
n = tp->n.elem;
for (sp = tp->p.fields; n--; ++sp) {
- (*sp)->u.i = size;
+ (*sp)->u.i = offset;
aux = (*sp)->type;
a = aux->align;
if (a > align)
@@ -212,8 +212,9 @@ typesize(Type *tp)
if (--a != 0)
size += (size + a) & ~a;
size += aux->size;
+ offset = size;
} else {
- if (tp->size > size)
+ if ((*sp)->type->size > size)
size = aux->size;
}
}