commit caa62432d65dbf35039908832765b7098f48a224
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Aug 25 23:39:41 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Aug 25 23:39:41 2015 +0200

    Fix calculation of sizes in structs
    
    The aligment calculus was wrong because we were taking
    the values from a wrong type pointer and because the
    phormula failed when size&align == 0.

diff --git a/cc1/types.c b/cc1/types.c
index c79a8f9..2bf3a84 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -279,11 +279,9 @@ typesize(Type *tp)
                n = tp->n.elem;
                for (sp = tp->p.fields; n--; ++sp) {
                        tp = (*sp)->type;
+                       align = tp->align-1;
+                       size = size + align & ~align;
                        size += tp->size;
-                       if (n > 0) {
-                               align = tp->align - 1;
-                               size += align - (size & align);
-                       }
                }
                return size;
        case UNION:

Reply via email to