diff --git a/tccgen.c b/tccgen.c index 0809760f..f493abf4 100644 --- a/tccgen.c +++ b/tccgen.c @@ -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"); diff --git a/tests/tests2/90_struct-init.c b/tests/tests2/90_struct-init.c index de8505d9..6bff8ab4 100644 --- a/tests/tests2/90_struct-init.c +++ b/tests/tests2/90_struct-init.c @@ -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; } diff --git a/tests/tests2/90_struct-init.expect b/tests/tests2/90_struct-init.expect index 45c8cf42..5014f821 100644 --- a/tests/tests2/90_struct-init.expect +++ b/tests/tests2/90_struct-init.expect @@ -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