ref: 9a4b6a26496c8bc3009d1e854f7891599761cb6a
parent: d8bea56691a536f08c04de1ae66fa4f145c9d2f0
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Sep 27 13:04:49 EDT 2016
[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.
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -176,7 +176,7 @@
{
Symbol **sp;
Type *aux;
- unsigned long size;
+ unsigned long size, offset;
int align, a;
TINT n;
@@ -200,10 +200,10 @@
* 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 @@
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;
}
}