]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix up handling of references to anon union members in initializers [PR53932]
authorJakub Jelinek <jakub@redhat.com>
Thu, 19 Jan 2023 22:27:34 +0000 (23:27 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 3 May 2023 12:02:37 +0000 (14:02 +0200)
commit04cf6b57c7c467f615a16b7bbda574671e3fb2df
treeae01e5e4f2419463b902f962c41b2c41a5693503
parent532cbd4d96285dce2440424faff30e5cc94954e4
c++: Fix up handling of references to anon union members in initializers [PR53932]

For anonymous union members we create artificial VAR_DECLs which
have DECL_VALUE_EXPR for the actual COMPONENT_REF.  That works
just fine inside of functions (including global dynamic constructors),
because during gimplification such VAR_DECLs are gimplified as
their DECL_VALUE_EXPR.  This is also done during regimplification.

But references to these artificial vars in DECL_INITIAL expressions
aren't ever replaced by the DECL_VALUE_EXPRs, so we end up either
with link failures like on the testcase below, or worse ICEs with
LTO.

The following patch fixes those during cp_fully_fold_init where we
already walk all the trees (!data->genericize means that
function rather than cp_fold_function).

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/53932
* cp-gimplify.c (cp_fold_r): During cp_fully_fold_init replace
DECL_ANON_UNION_VAR_P VAR_DECLs with their corresponding
DECL_VALUE_EXPR.

* g++.dg/init/pr53932.C: New test.

(cherry picked from commit 9b9a989adc042b304572fd6d4ade46b47be6ccb8)
gcc/cp/cp-gimplify.c
gcc/testsuite/g++.dg/init/pr53932.C [new file with mode: 0644]