Fix char bitfields corner case

See testcase.
This commit is contained in:
Michael Matz 2017-04-29 21:23:43 +02:00
parent 76e16465bf
commit 28084420fe
2 changed files with 7 additions and 1 deletions

View File

@ -3387,7 +3387,7 @@ static void struct_layout(CType *type, AttributeDef *ad)
int ofs = (c * 8 + bit_pos) % (typealign * 8);
int ofs2 = ofs + bit_size + (typealign * 8) - 1;
if (bit_size == 0 ||
(typealign != 1 &&
((typealign != 1 || size == 1) &&
(ofs2 / (typealign * 8)) > (size/typealign))) {
c = (c + ((bit_pos + 7) >> 3) + typealign - 1) & -typealign;
bit_pos = 0;

View File

@ -2069,6 +2069,12 @@ void bitfield_test(void)
} st3;
printf("sizeof(st3) = %d\n", sizeof(st3));
#endif
struct sbf4 {
int x : 31;
char y : 2;
} st4;
st4.y = 1;
printf("st4.y == %d\n", st4.y);
}
#ifdef __x86_64__