cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 5784264d0eec915ccf5e7a930ee85e36e3a12923
parent 5e8fa8708b65f633c011d3252d8372236acf9a7e
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 12 Feb 2019 14:05:30 -0800

Fix union sizes and member offsets

Diffstat:
Mdecl.c | 10++++++++--
Atests/union.c | 4++++
Atests/union.qbe | 2++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git 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; } diff --git a/tests/union.c b/tests/union.c @@ -0,0 +1,4 @@ +union { + int x; + double y; +} a = {.x = 5}, b = {.y = 7.5}; diff --git a/tests/union.qbe b/tests/union.qbe @@ -0,0 +1,2 @@ +export data $a = align 8 { w 5, z 4 } +export data $b = align 8 { d d_0x1.ep+2, }