commit dd69378b91c35a62d9e2960fbad9ae11e4a06ec4
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Sep 27 17:04:49 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Sep 27 17:04:49 2016 +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.

diff --git a/cc1/types.c b/cc1/types.c
index f4fa6f9..44deac6 100644
--- 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;
                        }
                }

Reply via email to