ref: 30c37c6b26a9be12a7e07628a170ba32d1861ef0
parent: e11e5f143419b049f2c93a4b361a668b57a77fc0
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Dec 28 20:43:27 EST 2015
Correct alignment of unions.
--- a/6/simp.c
+++ b/6/simp.c
@@ -95,28 +95,7 @@
size_t alignto(size_t sz, Type *t)
{
- size_t a;
- size_t i;
-
- t = tybase(t);
- a = 0;
- switch (t->type) {
- case Tyarray:
- a = alignto(1, t->sub[0]);
- case Tytuple:
- for (i = 0; i < t->nsub; i++)
- a = max(alignto(1, t->sub[i]), a);
- break;
- case Tystruct:
- for (i = 0; i < t->nmemb; i++)
- a = max(alignto(1, decltype(t->sdecls[i])), a);
- break;
- default:
- a = tysize(t);
- break;
- }
-
- return align(sz, min(a, Ptrsz));
+ return align(sz, tyalign(t));
}
static Type *base(Type *t)
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -295,7 +295,7 @@
for (i = 0; i < t->nmemb; i++)
if (t->udecls[i]->etype)
sz = max(sz, tysize(t->udecls[i]->etype) + Wordsz);
- return align(sz, Ptrsz);
+ return align(sz, tyalign(t));
break;
case Tygeneric: case Tybad: case Tyvar:
case Typaram: case Tyunres: case Ntypes:
@@ -310,6 +310,7 @@
size_t align, i;
align = 1;
+ ty = tybase(ty);
switch (ty->type) {
case Tyarray:
align = tyalign(ty->sub[0]);