This is the mail archive of the gcc-bugs@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]

[Bug fortran/20460] Nasty extensions that should always warn


------- Additional Comments From aoliva at gcc dot gnu dot org  2005-03-30 05:56 -------
Subject: [PR tree-optimization/20460] add phi args to dests of dce-redirected edges

When remove_dead_stmt() redirects a control stmt, the edge redirection
reserves space for the phi arg for the new incoming edge in all phi
nodes, but, instead of filling them in with information obtained from
the edge redirection, we simply discard this information.  This leaves
NULL in the phi args, which may cause crashes later on.

This patch fixes the problem by filling in the phi args using the
PENDING_STMT list created during edge redirection.  This appears to be
the intended use for this information, and it is used similarly in
e.g. loop unrolling.

Bootstrapping mainline and 4.0 branch on amd64-linux-gnu, and mainline
on i686-pc-linux-gnu.  Ok to install if bootstrap and regtesting pass?

The patch below is for the 4.0 branch, but it applies cleanly and
correctly in mainline as well, since it's just a few lines off.

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR tree-optimization/20460
	* tree-ssa-dce.c (remove_dead_stmt): Add phi args to phi nodes
	affected by an edge redirection.

Index: gcc/tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dce.c,v
retrieving revision 2.32
diff -u -p -r2.32 tree-ssa-dce.c
--- gcc/tree-ssa-dce.c 17 Feb 2005 16:19:44 -0000 2.32
+++ gcc/tree-ssa-dce.c 30 Mar 2005 05:28:09 -0000
@@ -810,7 +810,7 @@ remove_dead_stmt (block_stmt_iterator *i
 
       /* Redirect the first edge out of BB to reach POST_DOM_BB.  */
       redirect_edge_and_branch (EDGE_SUCC (bb, 0), post_dom_bb);
-      PENDING_STMT (EDGE_SUCC (bb, 0)) = NULL;
+      flush_pending_stmts (EDGE_SUCC (bb, 0));
       EDGE_SUCC (bb, 0)->probability = REG_BR_PROB_BASE;
       EDGE_SUCC (bb, 0)->count = bb->count;
 
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR tree-optimization/20640
	* gcc.dg/torture/tree-loop-1.c: New.

Index: gcc/testsuite/gcc.dg/torture/tree-loop-1.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/torture/tree-loop-1.c
diff -N gcc/testsuite/gcc.dg/torture/tree-loop-1.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/torture/tree-loop-1.c 30 Mar 2005 05:28:22 -0000
@@ -0,0 +1,21 @@
+/* PR tree-optimization/20640 */
+
+/* After unrolling the loop, we'd turn some conditional branches into
+   unconditional ones, but branch redirection would fail to compute
+   the PHI args for the PHI nodes in the replacement edge
+   destination, so they'd remain NULL causing crashes later on.  */
+
+/* { dg-do compile } */
+
+static int a = 0;
+extern int foo (void);
+extern int *bar (void) __attribute__ ((__const__));
+
+void
+test (int x)
+{
+  int b = 10;
+  while (foo () == -1 && *bar () == 4 && b > 0)
+    --b;
+  a = x;
+}

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20460


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