This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Handle new operators with no arguments in DCE.
- From: Martin Liška <mliska at suse dot cz>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Marc Glisse <marc dot glisse at inria dot fr>, David Malcolm <dmalcolm at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <richard dot guenther at gmail dot com>, dominik dot infuehr at theobroma-systems dot com
- Date: Mon, 5 Aug 2019 08:44:26 +0200
- Subject: [PATCH] Handle new operators with no arguments in DCE.
- References: <8305B5F4-2A96-4698-8C2E-3255658B5C12@theobroma-systems.com> <CAFiYyc2nZ4vSGa5d_ni0km2kwUtyd9+BScrKzxKdbhZV=t6d1g@mail.gmail.com> <20171122103742.GN14653@tucnak> <BC60F078-9257-4E4F-8D94-7C41F7C7B802@theobroma-systems.com> <ec89be92-a232-5e34-e482-493b9babb65b@gmail.com> <20171129083045.GX2353@tucnak> <f6e7d0ed-4709-5e66-5bec-16d4e7c61ac0@gmail.com> <1511972121.27881.39.camel@redhat.com> <alpine.DEB.2.21.1805131552200.22357@stedding.saclay.inria.fr> <0dd24714-1f35-6a80-c607-7c8a332e95b9@suse.cz> <993cd4f8-cc02-6934-b19b-5a313db0475c@suse.cz> <CAMe9rOo_ZNS_Gnxn93CPDfpmjnhMTRMwfqzATNdj7Pb9FAkJLQ@mail.gmail.com>
On 8/2/19 11:34 PM, H.J. Lu wrote:
> On Tue, Jul 2, 2019 at 4:50 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> Second part.
>>
>> Martin
>
> This caused:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91334
>
Hi.
I'm sending fix for the ICE. The issue is that we can end up
with a ctor without an argument (when not being used).
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
>From 76d215d59f32c5f6cbcb0a0ad4ecbfff8f181770 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 5 Aug 2019 06:55:45 +0200
Subject: [PATCH] Handle new operators with no arguments in DCE.
gcc/ChangeLog:
2019-08-05 Martin Liska <mliska@suse.cz>
PR c++/91334
* tree-ssa-dce.c (propagate_necessity): Handle new operators
with not arguments.
(eliminate_unnecessary_stmts): Likewise.
gcc/testsuite/ChangeLog:
2019-08-05 Martin Liska <mliska@suse.cz>
PR c++/91334
* g++.dg/torture/pr91334.C: New test.
---
gcc/testsuite/g++.dg/torture/pr91334.C | 14 ++++++++++++++
gcc/tree-ssa-dce.c | 22 ++++++++++++++++------
2 files changed, 30 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/torture/pr91334.C
diff --git a/gcc/testsuite/g++.dg/torture/pr91334.C b/gcc/testsuite/g++.dg/torture/pr91334.C
new file mode 100644
index 00000000000..ba79d712b07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr91334.C
@@ -0,0 +1,14 @@
+/* PR c++/91334. */
+/* { dg-do compile } */
+
+#include <new>
+#include <stdlib.h>
+
+struct A {
+ A() { throw 0; }
+ void* operator new(size_t size, double = 0.0) { return ::operator new(size);}
+ void operator delete(void* p, double) { exit(0); }
+ void operator delete(void* p) { abort(); }
+};
+
+int main() { try { new A; } catch(...) {} }
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index 80d5f5c30f7..afb7bd9dedc 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -810,6 +810,11 @@ propagate_necessity (bool aggressive)
if (is_delete_operator
|| gimple_call_builtin_p (stmt, BUILT_IN_FREE))
{
+ /* It can happen that a user delete operator has the pointer
+ argument optimized out already. */
+ if (gimple_call_num_args (stmt) == 0)
+ continue;
+
tree ptr = gimple_call_arg (stmt, 0);
gimple *def_stmt;
tree def_callee;
@@ -1323,13 +1328,18 @@ eliminate_unnecessary_stmts (void)
|| (is_gimple_call (stmt)
&& gimple_call_operator_delete_p (as_a <gcall *> (stmt)))))
{
- tree ptr = gimple_call_arg (stmt, 0);
- if (TREE_CODE (ptr) == SSA_NAME)
+ /* It can happen that a user delete operator has the pointer
+ argument optimized out already. */
+ if (gimple_call_num_args (stmt) > 0)
{
- gimple *def_stmt = SSA_NAME_DEF_STMT (ptr);
- if (!gimple_nop_p (def_stmt)
- && !gimple_plf (def_stmt, STMT_NECESSARY))
- gimple_set_plf (stmt, STMT_NECESSARY, false);
+ tree ptr = gimple_call_arg (stmt, 0);
+ if (TREE_CODE (ptr) == SSA_NAME)
+ {
+ gimple *def_stmt = SSA_NAME_DEF_STMT (ptr);
+ if (!gimple_nop_p (def_stmt)
+ && !gimple_plf (def_stmt, STMT_NECESSARY))
+ gimple_set_plf (stmt, STMT_NECESSARY, false);
+ }
}
}
--
2.22.0