]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/42508 (wrong code with "-O1 -fipa-sra")
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Jan 2010 08:40:50 +0000 (09:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Jan 2010 08:40:50 +0000 (09:40 +0100)
PR tree-optimization/42508
* tree-sra.c (convert_callers): Check for recursive call
by comparing cgraph nodes instead of decls.
(modify_function): Call ipa_modify_formal_parameters also
on all same_body aliases.

* g++.dg/opt/pr42508.C: New test.

* cgraphunit.c (cgraph_materialize_all_clones): Compare
cgraph nodes when checking for same_body aliases.

From-SVN: r155640

gcc/ChangeLog
gcc/cgraphunit.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr42508.C [new file with mode: 0644]
gcc/tree-sra.c

index da9ed1af3373fa90ef12294258f0749e4e05dfbf..b45e59c549793b15e0b2265ece528d338b5e12f3 100644 (file)
@@ -1,3 +1,14 @@
+2010-01-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/42508
+       * tree-sra.c (convert_callers): Check for recursive call
+       by comparing cgraph nodes instead of decls.
+       (modify_function): Call ipa_modify_formal_parameters also
+       on all same_body aliases.
+
+       * cgraphunit.c (cgraph_materialize_all_clones): Compare
+       cgraph nodes when checking for same_body aliases.
+
 2010-01-05  Richard Guenther  <rguenther@suse.de>
 
        * tree-ssa-pre.c (get_or_alloc_expr_for_name): Avoid redundant
index cf1a00154727fa35b717992c67f55ad9d7bfb111..ebe662ad63939f191c9fde4f4728fb80d57066d0 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph based interprocedural optimizations.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
@@ -2323,20 +2323,9 @@ cgraph_materialize_all_clones (void)
                gimple new_stmt;
                gimple_stmt_iterator gsi;
 
-               if (e->callee->same_body)
-                 {
-                   struct cgraph_node *alias;
-
-                   for (alias = e->callee->same_body;
-                        alias;
-                        alias = alias->next)
-                     if (decl == alias->decl)
-                       break;
-                   /* Don't update call from same body alias to the real
-                      function.  */
-                   if (alias)
-                     continue;
-                 }
+               if (cgraph_get_node (decl) == cgraph_get_node (e->callee->decl))
+                 /* Don't update call from same body alias to the real function.  */
+                 continue;
 
                if (cgraph_dump_file)
                  {
index 08622cb1fda2522c162572cf78eae37954091c25..89358798c846f124e231a7e7bc5fe0fd9ac461ec 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/42508
+       * g++.dg/opt/pr42508.C: New test.
+
 2010-01-05  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/41872
diff --git a/gcc/testsuite/g++.dg/opt/pr42508.C b/gcc/testsuite/g++.dg/opt/pr42508.C
new file mode 100644 (file)
index 0000000..68dd4c6
--- /dev/null
@@ -0,0 +1,33 @@
+// PR tree-optimization/42508
+// { dg-do run }
+// { dg-options "-O1 -fipa-sra" }
+
+extern "C" void abort ();
+
+int v[10], vidx;
+
+struct A
+{
+  A *prev;
+  int i;
+  ~A()
+  {
+    v[vidx++] = i;
+    delete prev;
+  }
+};
+
+int
+main ()
+{
+  A *a1 = new A ();
+  A *a2 = new A ();
+  a1->prev = 0;
+  a1->i = 1;
+  a2->prev = a1;
+  a2->i = 2;
+  delete a2;
+  if (vidx != 2 || v[0] != 2 || v[1] != 1)
+    abort ();
+  return 0;
+}
index f45169277e7608a8b23c5c2154bfbd67103bf07a..f0e874f2053e3cb99b17bd99a9a2e43088b98f46 100644 (file)
@@ -3800,8 +3800,11 @@ convert_callers (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments)
       for (gsi = gsi_start_bb (this_block); !gsi_end_p (gsi); gsi_next (&gsi))
         {
          gimple stmt = gsi_stmt (gsi);
-         if (gimple_code (stmt) == GIMPLE_CALL
-             && gimple_call_fndecl (stmt) == node->decl)
+         tree call_fndecl;
+         if (gimple_code (stmt) != GIMPLE_CALL)
+           continue;
+         call_fndecl = gimple_call_fndecl (stmt);
+         if (call_fndecl && cgraph_get_node (call_fndecl) == node)
            {
              if (dump_file)
                fprintf (dump_file, "Adjusting recursive call");
@@ -3819,6 +3822,11 @@ convert_callers (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments)
 static void
 modify_function (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments)
 {
+  struct cgraph_node *alias;
+  for (alias = node->same_body; alias; alias = alias->next)
+    ipa_modify_formal_parameters (alias->decl, adjustments, "ISRA");
+  /* current_function_decl must be handled last, after same_body aliases,
+     as following functions will use what it computed.  */
   ipa_modify_formal_parameters (current_function_decl, adjustments, "ISRA");
   scan_function (sra_ipa_modify_expr, sra_ipa_modify_assign,
                 replace_removed_params_ssa_names, false, adjustments);