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:
parent
c771cb52fa
commit
3f0a1719dc
3 changed files with 21 additions and 1 deletions
4
tccgen.c
4
tccgen.c
|
@ -7392,7 +7392,9 @@ static int decl_designator(init_params *p, CType *type, unsigned long c,
|
||||||
c += index * elem_size;
|
c += index * elem_size;
|
||||||
} else {
|
} else {
|
||||||
f = *cur_field;
|
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;
|
*cur_field = f = f->next;
|
||||||
if (!f)
|
if (!f)
|
||||||
tcc_error("too many initializers");
|
tcc_error("too many initializers");
|
||||||
|
|
|
@ -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()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -403,5 +419,6 @@ int main()
|
||||||
test_zero_init();
|
test_zero_init();
|
||||||
test_init_ranges();
|
test_init_ranges();
|
||||||
test_init_struct_from_struct();
|
test_init_struct_from_struct();
|
||||||
|
test_init_bf();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,3 +56,4 @@ sea_fill1: okay
|
||||||
sea_fill2: okay
|
sea_fill2: okay
|
||||||
1438
|
1438
|
||||||
test_init_struct_from_struct: 1 2 3 4 - 1 2 3 4 - 3 4 5 6
|
test_init_struct_from_struct: 1 2 3 4 - 1 2 3 4 - 3 4 5 6
|
||||||
|
test_init_bf: 1 2 3
|
||||||
|
|
Loading…
Reference in a new issue