* [pushed] c++: TARGET_EXPR collapsing [PR107303]
@ 2023-01-24 3:26 Jason Merrill
2023-01-24 23:16 ` [committed] testsuite: Fix up new51.C test on various targets [PR108533] Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2023-01-24 3:26 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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 | 31 +++++++++++++++++--
.../g++.dg/ext/builtin-shufflevector-5.C | 14 +++++++++
gcc/testsuite/g++.dg/init/new51.C | 10 ++++++
3 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C
create mode 100644 gcc/testsuite/g++.dg/init/new51.C
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 83ba1285bfd..92cd309e670 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -952,6 +952,28 @@ cp_genericize_target_expr (tree *stmt_p)
gcc_assert (!DECL_INITIAL (slot));
}
+/* Similar to if (target_expr_needs_replace) replace_decl, but TP is the
+ TARGET_EXPR_INITIAL, and this also updates *_SLOT. We need this extra
+ replacement when cp_folding TARGET_EXPR to preserve the invariant that
+ AGGR_INIT_EXPR_SLOT agrees with the enclosing TARGET_EXPR_SLOT. */
+
+bool
+maybe_replace_decl (tree *tp, tree decl, tree replacement)
+{
+ if (!*tp || !VOID_TYPE_P (TREE_TYPE (*tp)))
+ return false;
+ tree t = *tp;
+ while (TREE_CODE (t) == COMPOUND_EXPR)
+ t = TREE_OPERAND (t, 1);
+ if (TREE_CODE (t) == AGGR_INIT_EXPR)
+ replace_decl (&AGGR_INIT_EXPR_SLOT (t), decl, replacement);
+ else if (TREE_CODE (t) == VEC_INIT_EXPR)
+ replace_decl (&VEC_INIT_EXPR_SLOT (t), decl, replacement);
+ else
+ replace_decl (tp, decl, replacement);
+ return true;
+}
+
/* Genericization context. */
struct cp_genericize_data
@@ -1116,15 +1138,18 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
cp_genericize_target_expr (stmt_p);
/* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in
- that case, use it in place of this one. */
+ that case, strip it in favor of this one. */
if (tree &init = TARGET_EXPR_INITIAL (stmt))
{
cp_walk_tree (&init, cp_fold_r, data, NULL);
+ cp_walk_tree (&TARGET_EXPR_CLEANUP (stmt), cp_fold_r, data, NULL);
*walk_subtrees = 0;
if (TREE_CODE (init) == TARGET_EXPR)
{
- TARGET_EXPR_ELIDING_P (init) = TARGET_EXPR_ELIDING_P (stmt);
- *stmt_p = init;
+ tree sub = TARGET_EXPR_INITIAL (init);
+ maybe_replace_decl (&sub, TARGET_EXPR_SLOT (init),
+ TARGET_EXPR_SLOT (stmt));
+ init = sub;
}
}
break;
diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C
new file mode 100644
index 00000000000..06472b8d86b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C
@@ -0,0 +1,14 @@
+// PR c++/107303
+// { dg-options "-Wno-psabi" }
+
+typedef __attribute__((__vector_size__ (2))) unsigned short U;
+typedef __attribute__((__vector_size__ (8))) unsigned short V;
+
+U u0, u1, u2;
+V v;
+
+void
+foo (void)
+{
+ u0 *= +__builtin_shufflevector (__builtin_shufflevector (u1, v, 3, 1), u2, 0);
+}
diff --git a/gcc/testsuite/g++.dg/init/new51.C b/gcc/testsuite/g++.dg/init/new51.C
new file mode 100644
index 00000000000..d8b336476d9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new51.C
@@ -0,0 +1,10 @@
+// PR c++/107329
+
+struct RexxClass {
+ void *operator new(unsigned long, unsigned long, const char *, RexxClass *,
+ RexxClass *);
+ void operator delete(void *, unsigned long, const char *, RexxClass *,
+ RexxClass *);
+ RexxClass();
+};
+void createInstance() { new (sizeof(RexxClass), "", 0, 0) RexxClass; }
base-commit: 4cbc71691e47b1ca6b64feb0af678606705d2f92
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [committed] testsuite: Fix up new51.C test on various targets [PR108533]
2023-01-24 3:26 [pushed] c++: TARGET_EXPR collapsing [PR107303] Jason Merrill
@ 2023-01-24 23:16 ` Jakub Jelinek
2023-01-25 14:09 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2023-01-24 23:16 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Mon, Jan 23, 2023 at 10:26:14PM -0500, Jason Merrill via Gcc-patches wrote:
> * g++.dg/init/new51.C: New test.
The test fails on targets where size_t is not unsigned long
due to extra diagnostics.
As the testcase is tested in C++98 too, I'm not using decltype (sizeof 0)
but __SIZE_TYPE__.
Tested on x86_64-linux and i686-linux (plus verified with older snapshots
that it ICEs even with the change with both -m32/-m64), committed to
trunk as obvious.
2023-01-25 Jakub Jelinek <jakub@redhat.com>
PR c++/107329
PR testsuite/108533
* g++.dg/init/new51.C (size_t): New typedef.
(RexxClass::operator new, RexxClass::operator delete): Use size_t
instead of unsigned long.
--- gcc/testsuite/g++.dg/init/new51.C.jj 2023-01-24 11:10:13.000000000 +0100
+++ gcc/testsuite/g++.dg/init/new51.C 2023-01-25 00:05:10.767472447 +0100
@@ -1,9 +1,10 @@
// PR c++/107329
+typedef __SIZE_TYPE__ size_t;
struct RexxClass {
- void *operator new(unsigned long, unsigned long, const char *, RexxClass *,
+ void *operator new(size_t, size_t, const char *, RexxClass *,
RexxClass *);
- void operator delete(void *, unsigned long, const char *, RexxClass *,
+ void operator delete(void *, size_t, const char *, RexxClass *,
RexxClass *);
RexxClass();
};
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [committed] testsuite: Fix up new51.C test on various targets [PR108533]
2023-01-24 23:16 ` [committed] testsuite: Fix up new51.C test on various targets [PR108533] Jakub Jelinek
@ 2023-01-25 14:09 ` Jason Merrill
0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2023-01-25 14:09 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 1/24/23 18:16, Jakub Jelinek wrote:
> On Mon, Jan 23, 2023 at 10:26:14PM -0500, Jason Merrill via Gcc-patches wrote:
>> * g++.dg/init/new51.C: New test.
>
> The test fails on targets where size_t is not unsigned long
> due to extra diagnostics.
>
> As the testcase is tested in C++98 too, I'm not using decltype (sizeof 0)
> but __SIZE_TYPE__.
>
> Tested on x86_64-linux and i686-linux (plus verified with older snapshots
> that it ICEs even with the change with both -m32/-m64), committed to
> trunk as obvious.
Thanks.
> 2023-01-25 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/107329
> PR testsuite/108533
> * g++.dg/init/new51.C (size_t): New typedef.
> (RexxClass::operator new, RexxClass::operator delete): Use size_t
> instead of unsigned long.
>
> --- gcc/testsuite/g++.dg/init/new51.C.jj 2023-01-24 11:10:13.000000000 +0100
> +++ gcc/testsuite/g++.dg/init/new51.C 2023-01-25 00:05:10.767472447 +0100
> @@ -1,9 +1,10 @@
> // PR c++/107329
>
> +typedef __SIZE_TYPE__ size_t;
> struct RexxClass {
> - void *operator new(unsigned long, unsigned long, const char *, RexxClass *,
> + void *operator new(size_t, size_t, const char *, RexxClass *,
> RexxClass *);
> - void operator delete(void *, unsigned long, const char *, RexxClass *,
> + void operator delete(void *, size_t, const char *, RexxClass *,
> RexxClass *);
> RexxClass();
> };
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-25 14:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 3:26 [pushed] c++: TARGET_EXPR collapsing [PR107303] Jason Merrill
2023-01-24 23:16 ` [committed] testsuite: Fix up new51.C test on various targets [PR108533] Jakub Jelinek
2023-01-25 14:09 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).