mirror of https://github.com/rui314/chibicc
Handle zero-width bitfield member
This commit is contained in:
parent
54c2b3b18f
commit
17ea802cea
6
parse.c
6
parse.c
|
@ -2134,7 +2134,11 @@ static Type *struct_decl(Token **rest, Token *tok) {
|
||||||
int bits = 0;
|
int bits = 0;
|
||||||
|
|
||||||
for (Member *mem = ty->members; mem; mem = mem->next) {
|
for (Member *mem = ty->members; mem; mem = mem->next) {
|
||||||
if (mem->is_bitfield) {
|
if (mem->is_bitfield && mem->bit_width == 0) {
|
||||||
|
// Zero-width anonymous bitfield has a special meaning.
|
||||||
|
// It affects only alignment.
|
||||||
|
bits = align_to(bits, mem->ty->size * 8);
|
||||||
|
} else if (mem->is_bitfield) {
|
||||||
int sz = mem->ty->size;
|
int sz = mem->ty->size;
|
||||||
if (bits / (sz * 8) != (bits + mem->bit_width - 1) / (sz * 8))
|
if (bits / (sz * 8) != (bits + mem->bit_width - 1) / (sz * 8))
|
||||||
bits = align_to(bits, sz * 8);
|
bits = align_to(bits, sz * 8);
|
||||||
|
|
|
@ -48,6 +48,10 @@ int main() {
|
||||||
ASSERT(3, ({ T3 x={1,2,3}; ++x.b; }));
|
ASSERT(3, ({ T3 x={1,2,3}; ++x.b; }));
|
||||||
ASSERT(4, ({ T3 x={1,2,3}; ++x.c; }));
|
ASSERT(4, ({ T3 x={1,2,3}; ++x.c; }));
|
||||||
|
|
||||||
|
ASSERT(4, sizeof(struct {int a:3; int c:1; int c:5;}));
|
||||||
|
ASSERT(8, sizeof(struct {int a:3; int:0; int c:5;}));
|
||||||
|
ASSERT(4, sizeof(struct {int a:3; int:0;}));
|
||||||
|
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue