shithub: mc

Download patch

ref: e11e5f143419b049f2c93a4b361a668b57a77fc0
parent: 07f5aa5bbf9445c1ff188a6f75a6fa162119cc35
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Dec 28 12:30:52 EST 2015

Fix union alignment.

--- a/6/blob.c
+++ b/6/blob.c
@@ -233,14 +233,17 @@
 
 static size_t blobucon(Blob *seq, Htab *globls, Htab *strtab, Node *n)
 {
-	size_t sz;
+	size_t sz, pad;
 	Ucon *uc;
 
 	sz = 4;
 	uc = finducon(exprtype(n), n->expr.args[0]);
 	b(seq, mkblobi(Bti32, uc->id));
-	if (n->expr.nargs > 1)
+	if (n->expr.nargs > 1) {
+		pad = tyalign(exprtype(n->expr.args[1])) - sz;
+		sz += blobpad(seq, pad);
 		sz += blobrec(seq, globls, strtab, n->expr.args[1]);
+	}
 	sz += blobpad(seq, size(n) - sz);
 	return sz;
 }
--- a/6/isel.c
+++ b/6/isel.c
@@ -809,7 +809,7 @@
 	case Ovjmp:
 			 selvjmp(s, n, args);
 			 break;
-	case Olit: /* fall through */
+	case Olit:
 			 r = loc(s, n);
 			 break;
 	case Ovar:
@@ -835,7 +835,7 @@
 			 clear(s, a, args[1]->expr.args[0]->lit.intval, 0);
 			 break;
 
-			 /* cast operators that actually modify the values */
+	/* cast operators that actually modify the values */
 	case Otrunc:
 			 a = selexpr(s, args[0]);
 			 a = inr(s, a);
--- a/6/simp.c
+++ b/6/simp.c
@@ -1155,7 +1155,7 @@
 	Node *r;
 	Type *ty;
 	Ucon *uc;
-	size_t i;
+	size_t i, o;
 
 	/* find the ucon we're constructing here */
 	ty = tybase(n->expr.type);
@@ -1185,7 +1185,8 @@
 	if (!uc->etype)
 		return tmp;
 	elt = rval(s, n->expr.args[1], NULL);
-	u = addk(u, Wordsz);
+	o = alignto(Wordsz, uc->etype);
+	u = addk(u, o);
 	if (isstacktype(uc->etype)) {
 		elt = addr(s, elt, uc->etype);
 		sz = disp(n->loc, tysize(uc->etype));
@@ -1200,11 +1201,13 @@
 static Node *simpuget(Simp *s, Node *n, Node *dst)
 {
 	Node *u, *p, *l;
+	size_t o;
 
 	if (!dst)
 		dst = temp(s, n);
 	u = rval(s, n->expr.args[0], NULL);
-	p = addk(addr(s, u, exprtype(n)), Wordsz);
+	o = alignto(Wordsz, exprtype(n));
+	p = addk(addr(s, u, exprtype(n)), o);
 	l = assign(s, dst, load(p));
 	append(s, l);
 	return dst;