c++: TARGET_EXPR collapsing [PR107303]
commit049a52909075117f5112971cc83952af2a818bc1
authorJason Merrill <jason@redhat.com>
Mon, 23 Jan 2023 21:25:07 +0000 (23 16:25 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 24 Jan 2023 03:26:24 +0000 (23 22:26 -0500)
treebc657540f19ed98d8f7fe778deebdb78f4b6f20d
parent607f278a3546fe6b91a881318db85d7a0dfdacd9
c++: TARGET_EXPR collapsing [PR107303]

In r13-2978 I tried to eliminate TARGET_EXPR around TARGET_EXPR by
discarding the outer one, but as in this testcase that breaks if the
TARGET_EXPR_SLOT of the outer one is used elsewhere.  But it should always
be safe to strip the inner one; if its slot were reused, there would be a
COMPOUND_EXPR around the TARGET_EXPR.

For 107329, if we're setting *walk_subtrees, we also need to fold
TARGET_EXPR_CLEANUP.

PR c++/107303
PR c++/107329

gcc/cp/ChangeLog:

* cp-gimplify.cc (cp_fold_r) [TARGET_EXPR]: In case of double
TARGET_EXPR, keep the outer one instead of the inner one.
(maybe_replace_decl): New.

gcc/testsuite/ChangeLog:

* g++.dg/ext/builtin-shufflevector-5.C: New test.
* g++.dg/init/new51.C: New test.
gcc/cp/cp-gimplify.cc
gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/new51.C [new file with mode: 0644]