This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A latent bug - use of BRANCH_EDGE on trees.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: dvorakz at suse dot cz
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 24 Oct 2004 14:08:50 -0400 (EDT)
- Subject: A latent bug - use of BRANCH_EDGE on trees.
Hi Zdenek,
I think I found a latent bug.
loopify in cfgloopmanip.c is called from tree_ssa_loop_version and
unswitch_loop. Of those, tree_ssa_loop_version obviously deals with
trees in SSA form.
Now, the problem is that loopify uses BRANCH_EDGE. While we are in
trees, EDGE_FALLTHRU does not make sense for basic blocks ending with
COND_EXPR. Here is the definition of BRANCH_EDGE.
#define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
Any ideas?
I found this latent bug while trying to use VEC_safe_push instead of
VEC_safe_insert to insert an edge to an edge vector. Here is a
testcase.
void bar (void);
void
foo (int x)
{
goto L1;
L0:
bar ();
L1:
if (x == 0) goto L0; else goto L2;
L2:
if (x == 1) goto L0; else goto L3;
L3:
return;
}
I attach my VEC_safe_push patch for completeness.
If this is indeed a latent bug, we should probably use something like
gcc_assert (ir_type () == 1);
in FALLTHRU_EDGE and BRANCH_EDGE to ensure that we don't use them in
trees.
Kazu Hirata
2004-10-24 Kazu Hirata <kazu@cs.umass.edu>
* cfg.c (unchecked_make_edge, redirect_edge_succ,
redirect_edge_pred): Use VEC_safe_push instead of
VEC_safe_insert.
* cfgrtl.c (force_nonfallthru_and_redirect): Likewise.
Index: cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfg.c,v
retrieving revision 1.71
diff -u -p -r1.71 cfg.c
--- cfg.c 22 Oct 2004 22:55:47 -0000 1.71
+++ cfg.c 24 Oct 2004 00:27:29 -0000
@@ -270,8 +270,8 @@ unchecked_make_edge (basic_block src, ba
e = ggc_alloc_cleared (sizeof (*e));
n_edges++;
- VEC_safe_insert (edge, src->succs, 0, e);
- VEC_safe_insert (edge, dst->preds, 0, e);
+ VEC_safe_push (edge, src->succs, e);
+ VEC_safe_push (edge, dst->preds, e);
e->src = src;
e->dest = dst;
@@ -418,7 +418,7 @@ redirect_edge_succ (edge e, basic_block
gcc_assert (found);
/* Reconnect the edge to the new successor block. */
- VEC_safe_insert (edge, new_succ->preds, 0, e);
+ VEC_safe_push (edge, new_succ->preds, e);
e->dest = new_succ;
}
@@ -476,7 +476,7 @@ redirect_edge_pred (edge e, basic_block
gcc_assert (found);
/* Reconnect the edge to the new predecessor block. */
- VEC_safe_insert (edge, new_pred->succs, 0, e);
+ VEC_safe_push (edge, new_pred->succs, e);
e->src = new_pred;
}
Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.140
diff -u -p -r1.140 cfgrtl.c
--- cfgrtl.c 22 Oct 2004 22:55:47 -0000 1.140
+++ cfgrtl.c 24 Oct 2004 00:27:29 -0000
@@ -1069,7 +1069,7 @@ force_nonfallthru_and_redirect (edge e,
gcc_assert (found);
- VEC_safe_insert (edge, bb->succs, 0, e);
+ VEC_safe_push (edge, bb->succs, e);
make_single_succ_edge (ENTRY_BLOCK_PTR, bb, EDGE_FALLTHRU);
}
}