c: Assorted fixes for flexible array members in unions [PR119001]
r15-209 allowed flexible array members inside of unions, but as the following testcase shows, not everything has been adjusted for that. Unlike structures, in unions flexible array member (as an extension) can be any of the members, not just the last one, as in union all members are effectively last. The first hunk is about an ICE on the initialization of the FAM in union which is not the last FIELD_DECL with a string literal, the second hunk just formatting fix, third hunk fixes a bug in which we were just throwing away the initializers (except for with string literal) of FAMs in unions which aren't the last FIELD_DECL, and the last hunk is to diagnose FAM errors in unions the same as for structures, in particular trying to initialize a FAM with non-constant or initialization in nested context. 2025-02-26 Jakub Jelinek <jakub@redhat.com> PR c/119001 gcc/ * varasm.cc (output_constructor_regular_field): Don't fail assertion if next is non-NULL and FIELD_DECL if TREE_CODE (local->type) is UNION_TYPE. gcc/c/ * c-typeck.cc (pop_init_level): Don't clear constructor_type if DECL_CHAIN of constructor_fields is NULL but p->type is UNION_TYPE. Formatting fix. (process_init_element): Diagnose non-static initialization of flexible array member in union or FAM in union initialization in nested context. gcc/testsuite/ * gcc.dg/pr119001-1.c: New test. * gcc.dg/pr119001-2.c: New test.
Showing
- gcc/c/c-typeck.cc 40 additions, 2 deletionsgcc/c/c-typeck.cc
- gcc/testsuite/gcc.dg/pr119001-1.c 35 additions, 0 deletionsgcc/testsuite/gcc.dg/pr119001-1.c
- gcc/testsuite/gcc.dg/pr119001-2.c 20 additions, 0 deletionsgcc/testsuite/gcc.dg/pr119001-2.c
- gcc/varasm.cc 6 additions, 3 deletionsgcc/varasm.cc
Loading
Please register or sign in to comment