This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Come up with function_decl_type and use it in tree_function_decl.


On 7/25/19 3:30 PM, Martin Liška wrote:
> On 7/25/19 2:18 PM, Marc Glisse wrote:
>> On Thu, 25 Jul 2019, Martin Liška wrote:
>>
>>>> DCE has special code to avoid removing the LHS of malloc when it is unused. Is there something different about operator new that makes it not need the same handling?
>>
>> If you take gcc.dg/torture/pr51692.c and replace __builtin_calloc (1, sizeof (double)) with new double(), we get an ICE with -O or higher...
>>
> 
> I can see, I'm working on that.
> 
> Martin
> 

There's a patch candidate I've been testing right now.

Ready to be installed after tests?
Thanks,
Martin
>From 4a7d515eda8591277dad01e1cd43a33883f2dcef Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 25 Jul 2019 17:24:51 +0200
Subject: [PATCH] Fix ICE seen in tree-ssa-dce.c for new/delete pair.

gcc/ChangeLog:

2019-07-25  Martin Liska  <mliska@suse.cz>

	* tree-ssa-dce.c (eliminate_unnecessary_stmts): Do not
	remove LHS of operator new call.  It's handled latter.

gcc/testsuite/ChangeLog:

2019-07-25  Martin Liska  <mliska@suse.cz>

	* g++.dg/cpp1y/new1.C (test_unused): Add new case that causes
	ICE.
---
 gcc/testsuite/g++.dg/cpp1y/new1.C |  8 ++++++++
 gcc/tree-ssa-dce.c                | 13 +++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/g++.dg/cpp1y/new1.C b/gcc/testsuite/g++.dg/cpp1y/new1.C
index a95dd4d1ee3..5e4f1bf6b0b 100644
--- a/gcc/testsuite/g++.dg/cpp1y/new1.C
+++ b/gcc/testsuite/g++.dg/cpp1y/new1.C
@@ -61,5 +61,13 @@ new_array_load() {
   delete [] x;
 }
 
+void
+test_unused() {
+  volatile double d = 0.0;
+  double *p = new double ();
+  d += 1.0;
+  delete p;
+}
+
 /* { dg-final { scan-tree-dump-times "Deleting : operator delete" 5 "cddce1"} } */
 /* { dg-final { scan-tree-dump-times "Deleting : _\\d+ = operator new" 7 "cddce1"} } */
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index 90b3f4d7c45..cf507fa0453 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -1341,12 +1341,13 @@ eliminate_unnecessary_stmts (void)
 		     did not mark as necessary, it will confuse the
 		     special logic we apply to malloc/free pair removal.  */
 		  && (!(call = gimple_call_fndecl (stmt))
-		      || DECL_BUILT_IN_CLASS (call) != BUILT_IN_NORMAL
-		      || (DECL_FUNCTION_CODE (call) != BUILT_IN_ALIGNED_ALLOC
-			  && DECL_FUNCTION_CODE (call) != BUILT_IN_MALLOC
-			  && DECL_FUNCTION_CODE (call) != BUILT_IN_CALLOC
-			  && !ALLOCA_FUNCTION_CODE_P
-			      (DECL_FUNCTION_CODE (call)))))
+		      || ((DECL_BUILT_IN_CLASS (call) != BUILT_IN_NORMAL
+			   || (DECL_FUNCTION_CODE (call) != BUILT_IN_ALIGNED_ALLOC
+			       && DECL_FUNCTION_CODE (call) != BUILT_IN_MALLOC
+			       && DECL_FUNCTION_CODE (call) != BUILT_IN_CALLOC
+			       && !ALLOCA_FUNCTION_CODE_P
+			       (DECL_FUNCTION_CODE (call))))
+			  && !DECL_IS_REPLACEABLE_OPERATOR_NEW_P (call))))
 		{
 		  something_changed = true;
 		  if (dump_file && (dump_flags & TDF_DETAILS))
-- 
2.22.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]