aboutsummaryrefslogtreecommitdiff
path: root/decl.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-12 14:05:30 -0800
committerMichael Forney <mforney@mforney.org>2019-02-12 14:06:16 -0800
commit5784264d0eec915ccf5e7a930ee85e36e3a12923 (patch)
tree2246f9187a9198faa2000bce208a382a1642794d /decl.c
parent5e8fa8708b65f633c011d3252d8372236acf9a7e (diff)
Fix union sizes and member offsets
Diffstat (limited to 'decl.c')
-rw-r--r--decl.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/decl.c b/decl.c
index 31eb0b9..235c975 100644
--- a/decl.c
+++ b/decl.c
@@ -660,8 +660,14 @@ structdecl(struct scope *s, struct type *t)
if (align < m->type->align)
align = m->type->align;
t->size = ALIGNUP(t->size, align);
- m->offset = t->size;
- t->size += m->type->size;
+ if (t->kind == TYPESTRUCT) {
+ m->offset = t->size;
+ t->size += m->type->size;
+ } else {
+ m->offset = 0;
+ if (t->size < m->type->size)
+ t->size = m->type->size;
+ }
if (t->align < align)
t->align = align;
}