]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/59330 (Crash in is_gimple_reg_type)
authorRichard Biener <rguenther@suse.de>
Thu, 28 Nov 2013 14:52:44 +0000 (14:52 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 28 Nov 2013 14:52:44 +0000 (14:52 +0000)
2013-11-28  Richard Biener  <rguenther@suse.de>

PR tree-optimization/59330
* tree-ssa-dce.c (eliminate_unnecessary_stmts): Simplify
and fix delayed marking of free calls not necessary.

* gcc.dg/torture/pr59330.c: New testcase.

From-SVN: r205486

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr59330.c [new file with mode: 0644]
gcc/tree-ssa-dce.c

index 507f8627315517b946c69c24f07940bac301a55f..cac4cc119751fa318db052143ce17b848c3f615f 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59330
+       * tree-ssa-dce.c (eliminate_unnecessary_stmts): Simplify
+       and fix delayed marking of free calls not necessary.
+
 2013-11-28  Andrew MacLeod  <amacleod@redhat.com>
 
        * tree-ssa-propagate.c (valid_gimple_call_p): Pass TREE_TYPE to
index c4f749e721254dd25c307f94bc615f1ac167e3c9..32061521ff5abbb2682e7e8f7046ef181e7b6e46 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59330
+       * gcc.dg/torture/pr59330.c: New testcase.
+
 2013-11-28  Richard Biener  <rguenther@suse.de>
 
        PR lto/59323
diff --git a/gcc/testsuite/gcc.dg/torture/pr59330.c b/gcc/testsuite/gcc.dg/torture/pr59330.c
new file mode 100644 (file)
index 0000000..74b832e
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+
+void free(void *ptr)
+{
+}
+
+void *foo(void)
+{
+  return 0;
+}
+
+int main(void)
+{
+  void *p = foo();
+  free(p);
+  return 0;
+}
index 61c5af62cedb15fe8758d743a5327df16a4dd8ed..e2177fed99c6fbf04b2a5f181092f5d889020bd2 100644 (file)
@@ -1191,26 +1191,18 @@ eliminate_unnecessary_stmts (void)
          stats.total++;
 
          /* We can mark a call to free as not necessary if the
-            defining statement of its argument is an allocation
-            function and that is not necessary itself.  */
-         if (gimple_call_builtin_p (stmt, BUILT_IN_FREE))
+            defining statement of its argument is not necessary
+            (and thus is getting removed).  */
+         if (gimple_plf (stmt, STMT_NECESSARY)
+             && gimple_call_builtin_p (stmt, BUILT_IN_FREE))
            {
              tree ptr = gimple_call_arg (stmt, 0);
-             tree callee2;
-             gimple def_stmt;
-             if (TREE_CODE (ptr) != SSA_NAME)
-               continue;
-             def_stmt = SSA_NAME_DEF_STMT (ptr);
-             if (!is_gimple_call (def_stmt)
-                 || gimple_plf (def_stmt, STMT_NECESSARY))
-               continue;
-             callee2 = gimple_call_fndecl (def_stmt);
-             if (callee2 == NULL_TREE
-                 || DECL_BUILT_IN_CLASS (callee2) != BUILT_IN_NORMAL
-                 || (DECL_FUNCTION_CODE (callee2) != BUILT_IN_MALLOC
-                     && DECL_FUNCTION_CODE (callee2) != BUILT_IN_CALLOC))
-               continue;
-             gimple_set_plf (stmt, STMT_NECESSARY, false);
+             if (TREE_CODE (ptr) == SSA_NAME)
+               {
+                 gimple def_stmt = SSA_NAME_DEF_STMT (ptr);
+                 if (!gimple_plf (def_stmt, STMT_NECESSARY))
+                   gimple_set_plf (stmt, STMT_NECESSARY, false);
+               }
            }
 
          /* If GSI is not necessary then remove it.  */