Fix init bitfield padding with size 32/64

The init code did not work for padding bitfields with size 32 and 64.
This commit is contained in:
herman ten brugge 2023-03-09 15:53:48 +01:00
parent c771cb52fa
commit 3f0a1719dc
3 changed files with 21 additions and 1 deletions

View file

@ -7392,7 +7392,9 @@ static int decl_designator(init_params *p, CType *type, unsigned long c,
c += index * elem_size;
} else {
f = *cur_field;
while (f && (f->v & SYM_FIRST_ANOM) && (f->type.t & VT_BITFIELD))
/* Skip bitfield padding. Also with size 32 and 64. */
while (f && (f->v & SYM_FIRST_ANOM) &&
is_integer_btype(f->type.t & VT_BTYPE))
*cur_field = f = f->next;
if (!f)
tcc_error("too many initializers");

View file

@ -371,6 +371,22 @@ void test_init_struct_from_struct(void)
);
}
typedef struct {
unsigned int a;
unsigned int : 32;
unsigned int b;
unsigned long : 64;
unsigned int c;
} tst_bf;
tst_bf arr[] = { { 1, 2, 3 } };
void
test_init_bf(void)
{
printf ("%s: %d %d %d\n", __FUNCTION__, arr[0].a, arr[0].b, arr[0].c);
}
int main()
{
@ -403,5 +419,6 @@ int main()
test_zero_init();
test_init_ranges();
test_init_struct_from_struct();
test_init_bf();
return 0;
}

View file

@ -56,3 +56,4 @@ sea_fill1: okay
sea_fill2: okay
1438
test_init_struct_from_struct: 1 2 3 4 - 1 2 3 4 - 3 4 5 6
test_init_bf: 1 2 3