]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Assorted fixes for flexible array members in unions [PR119001]
authorJakub Jelinek <jakub@redhat.com>
Wed, 26 Feb 2025 18:31:08 +0000 (19:31 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 26 Feb 2025 18:31:08 +0000 (19:31 +0100)
commitad2908ed4ec5eff3cad3fd142cde5c1fac4788e9
tree80476832cc79d7d0092de3aefb89b3275ba9e8d5
parent8d22474af76a386eed488b3c66124134f0e41363
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.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr119001-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr119001-2.c [new file with mode: 0644]
gcc/varasm.cc