mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-10 08:50:07 +08:00
Fix more bitfield corner cases
Our code generation assumes that it can load/store with the bit-fields base type, so bit_pos/bit_size must be in range for this. We could change the fields type or adjust offset/bit_pos; we do the latter.
This commit is contained in:
parent
4ce73354fc
commit
8d9dd3c008
3
tccgen.c
3
tccgen.c
@ -3391,6 +3391,9 @@ static void struct_layout(CType *type, AttributeDef *ad)
|
||||
(ofs2 / (typealign * 8)) > (size/typealign))) {
|
||||
c = (c + ((bit_pos + 7) >> 3) + typealign - 1) & -typealign;
|
||||
bit_pos = 0;
|
||||
} else while (bit_pos + bit_size > size * 8) {
|
||||
c += size;
|
||||
bit_pos -= size * 8;
|
||||
}
|
||||
offset = c;
|
||||
/* In PCC layout named bit-fields influence the alignment
|
||||
|
@ -2082,6 +2082,12 @@ void bitfield_test(void)
|
||||
char c;
|
||||
} st5 = { 1, 2, 3, 4, -3, 6 };
|
||||
printf("st5 = %d %d %d %d %d %d\n", st5.a, st5.b, st5.x, st5.y, st5.z, st5.c);
|
||||
struct sbf6 {
|
||||
short x : 12;
|
||||
unsigned char y : 2;
|
||||
} st6;
|
||||
st6.y = 1;
|
||||
printf("st6.y == %d\n", st6.y);
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
Loading…
Reference in New Issue
Block a user