mirror of
https://github.com/frida/tinycc
synced 2025-01-12 14:49:18 +03:00
Fix char bitfields corner case
See testcase.
This commit is contained in:
parent
76e16465bf
commit
28084420fe
2
tccgen.c
2
tccgen.c
@ -3387,7 +3387,7 @@ static void struct_layout(CType *type, AttributeDef *ad)
|
|||||||
int ofs = (c * 8 + bit_pos) % (typealign * 8);
|
int ofs = (c * 8 + bit_pos) % (typealign * 8);
|
||||||
int ofs2 = ofs + bit_size + (typealign * 8) - 1;
|
int ofs2 = ofs + bit_size + (typealign * 8) - 1;
|
||||||
if (bit_size == 0 ||
|
if (bit_size == 0 ||
|
||||||
(typealign != 1 &&
|
((typealign != 1 || size == 1) &&
|
||||||
(ofs2 / (typealign * 8)) > (size/typealign))) {
|
(ofs2 / (typealign * 8)) > (size/typealign))) {
|
||||||
c = (c + ((bit_pos + 7) >> 3) + typealign - 1) & -typealign;
|
c = (c + ((bit_pos + 7) >> 3) + typealign - 1) & -typealign;
|
||||||
bit_pos = 0;
|
bit_pos = 0;
|
||||||
|
@ -2069,6 +2069,12 @@ void bitfield_test(void)
|
|||||||
} st3;
|
} st3;
|
||||||
printf("sizeof(st3) = %d\n", sizeof(st3));
|
printf("sizeof(st3) = %d\n", sizeof(st3));
|
||||||
#endif
|
#endif
|
||||||
|
struct sbf4 {
|
||||||
|
int x : 31;
|
||||||
|
char y : 2;
|
||||||
|
} st4;
|
||||||
|
st4.y = 1;
|
||||||
|
printf("st4.y == %d\n", st4.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
Loading…
Reference in New Issue
Block a user