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 2b34742bf0dbabbdb7335838902323df66974b39
parent 1ef0706e1f2e97d0872eb801169de5023c3c8b7f
Author: Michael Forney <mforney@mforney.org>
Date:   Sat, 27 Apr 2019 20:33:56 -0700

Unnamed bit-fields don't contribute to size or alignment of unions, or size of structs

Diffstat:
Mdecl.c | 12+++++-------
Atest/bitfield-unnamed-size-align.c | 12++++++++++++
Atest/bitfield-unnamed-size-align.qbe | 4++++
3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/decl.c b/decl.c @@ -714,17 +714,15 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, ui } t->size += (width - b->bits + 7) / 8; b->bits = (b->bits - width) % 8; - } else { - if (m) { - m->offset = 0; - m->bits.before = 0; - m->bits.after = mt.type->size * 8 - width; - } + } else if (m) { + m->offset = 0; + m->bits.before = 0; + m->bits.after = mt.type->size * 8 - width; if (t->size < mt.type->size) t->size = mt.type->size; } } - if (t->align < align) + if (m && t->align < align) t->align = align; } diff --git a/test/bitfield-unnamed-size-align.c b/test/bitfield-unnamed-size-align.c @@ -0,0 +1,12 @@ +struct s { + int : 8; + char c; +}; +union u { + int : 8; + char c; +}; +int s1 = sizeof(struct s); +int s2 = _Alignof(struct s); +int u1 = sizeof(union u); +int u2 = _Alignof(union u); diff --git a/test/bitfield-unnamed-size-align.qbe b/test/bitfield-unnamed-size-align.qbe @@ -0,0 +1,4 @@ +export data $s1 = align 4 { w 2, } +export data $s2 = align 4 { w 1, } +export data $u1 = align 4 { w 1, } +export data $u2 = align 4 { w 1, }