Hi.

And there's one more patch that deals with delete operator
which has a second argument (size). That definition GIMPLE
statement of the size must be also properly marked.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin
>From 3d69c779ad5de447cd5ddba2595d2b1586dc5d3c Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Sun, 28 Jul 2019 13:04:28 +0200
Subject: [PATCH] Remove also 2nd argument for unused delete operator (PR
 tree-optimization/91270).

gcc/ChangeLog:

2019-07-28  Martin Liska  <mli...@suse.cz>

	PR tree-optimization/91270
	* tree-ssa-dce.c (eliminate_unnecessary_stmts): Delete also 2nd
	argument of a delete operator.

gcc/testsuite/ChangeLog:

2019-07-28  Martin Liska  <mli...@suse.cz>

	PR tree-optimization/91270
	* g++.dg/torture/pr91270.C: New test.
---
 gcc/testsuite/g++.dg/torture/pr91270.C | 10 ++++++++++
 gcc/tree-ssa-dce.c                     | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr91270.C

diff --git a/gcc/testsuite/g++.dg/torture/pr91270.C b/gcc/testsuite/g++.dg/torture/pr91270.C
new file mode 100644
index 00000000000..60d766e9e9f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr91270.C
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+struct S {
+  ~S();
+};
+int a = 123;
+void fn1() {
+  S *s = new S[a];
+  delete[] s;
+}
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index cf507fa0453..e5a1a9b7aa3 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -1294,6 +1294,20 @@ eliminate_unnecessary_stmts (void)
 		      && !gimple_plf (def_stmt, STMT_NECESSARY))
 		    gimple_set_plf (stmt, STMT_NECESSARY, false);
 		}
+
+	      /* Some delete operators have 2 arguments, where
+		 the second argument is size of the deallocated memory.  */
+	      if (gimple_call_num_args (stmt) == 2)
+		{
+		  tree ptr = gimple_call_arg (stmt, 1);
+		  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);
+		    }
+		}
 	    }
 
 	  /* If GSI is not necessary then remove it.  */
-- 
2.22.0

Reply via email to