Mark 2nd argument of delete operator as needed (PR tree-optimization/91270).
authorMartin Liska <mliska@suse.cz>
Tue, 30 Jul 2019 11:00:35 +0000 (13:00 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 30 Jul 2019 11:00:35 +0000 (11:00 +0000)
2019-07-30  Martin Liska  <mliska@suse.cz>

PR tree-optimization/91270
* tree-ssa-dce.c (propagate_necessity): Mark 2nd argument
of delete operator as needed.
2019-07-30  Martin Liska  <mliska@suse.cz>

PR tree-optimization/91270
* g++.dg/torture/pr91270.C: New test.

From-SVN: r273906

gcc/cp/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr91270.C [new file with mode: 0644]
gcc/tree-ssa-dce.c

index eeed3dcef55d968db519730d3353ec92218145e9..425eea11a7cb17b6b17a2223b12278eb847aecff 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-30  Martin Liska  <mliska@suse.cz>
+
+       PR tree-optimization/91270
+       * tree-ssa-dce.c (propagate_necessity): Mark 2nd argument
+       of delete operator as needed.
+
 2019-07-25  Martin Liska  <mliska@suse.cz>
            Dominik Infuhr  <dominik.infuehr@theobroma-systems.com>
 
index 5a856986db4860eabefa322a08b50bed89465edc..bad5687182392feb22178f32a313590f5110d1c4 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-30  Martin Liska  <mliska@suse.cz>
+
+       PR tree-optimization/91270
+       * g++.dg/torture/pr91270.C: New test.
+
 2019-07-30  Richard Sandiford  <richard.sandiford@arm.com>
 
        * gcc.dg/vect/vect-cond-arith-7.c: New test.
diff --git a/gcc/testsuite/g++.dg/torture/pr91270.C b/gcc/testsuite/g++.dg/torture/pr91270.C
new file mode 100644 (file)
index 0000000..60d766e
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+struct S {
+  ~S();
+};
+int a = 123;
+void fn1() {
+  S *s = new S[a];
+  delete[] s;
+}
index 763b76f0e5325519ff98a1b4036d39c9272ea569..bec13cd593092ba67e2413f26b7dd3119179e3fb 100644 (file)
@@ -804,10 +804,11 @@ propagate_necessity (bool aggressive)
          /* If this is a call to free which is directly fed by an
             allocation function do not mark that necessary through
             processing the argument.  */
-         if (gimple_call_builtin_p (stmt, BUILT_IN_FREE)
-             || (is_gimple_call (stmt)
-                 && gimple_call_operator_delete_p (as_a <gcall *> (stmt))))
-
+         bool is_delete_operator
+           = (is_gimple_call (stmt)
+              && gimple_call_operator_delete_p (as_a <gcall *> (stmt)));
+         if (is_delete_operator
+             || gimple_call_builtin_p (stmt, BUILT_IN_FREE))
            {
              tree ptr = gimple_call_arg (stmt, 0);
              gimple *def_stmt;
@@ -822,7 +823,17 @@ propagate_necessity (bool aggressive)
                           || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_MALLOC
                           || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC))
                      || DECL_IS_REPLACEABLE_OPERATOR_NEW_P (def_callee)))
-               continue;
+               {
+                 /* Some delete operators have size as 2nd argument.  */
+                 if (is_delete_operator && gimple_call_num_args (stmt) >= 2)
+                   {
+                     tree size_argument = gimple_call_arg (stmt, 1);
+                     if (TREE_CODE (size_argument) == SSA_NAME)
+                       mark_operand_necessary (size_argument);
+                   }
+
+                 continue;
+               }
            }
 
          FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)