shithub: scc

Download patch

ref: caa62432d65dbf35039908832765b7098f48a224
parent: 5333c3cfde5f199f893cf52c4476f173b672bba0
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 25 19:39:41 EDT 2015

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.

--- a/cc1/types.c
+++ b/cc1/types.c
@@ -279,11 +279,9 @@
 		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: