This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa-cfg] BIND_EXPR removal
On Tue, 2003-10-07 at 14:47, Daniel Berlin wrote:
>
> On Oct 7, 2003, at 2:37 PM, Andrew MacLeod wrote:
>
> >
> > Look at where case 114: is..... is that truly allowed? especially
> > *after* the default label????
> whoa.
> that *is* weird.
> I didn't even notice.
how irritating. So, a hunk of code/situation as ugly as this deserves a
really ugly fix :-)
we're in the bmiddle of processing a list of preds when this happens,
and the new split is going to cause our list to change in mid loop. irk.
Give this a shot. This is just rude :-)
If'n it works for you and solves your problem, I'll consider checking it
in, ugliness and all :-)
Andrew
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.173
diff -c -p -r1.1.4.173 tree-cfg.c
*** tree-cfg.c 6 Oct 2003 14:34:25 -0000 1.1.4.173
--- tree-cfg.c 7 Oct 2003 19:46:17 -0000
*************** handle_switch_split (basic_block src, ba
*** 3780,3799 ****
/* Insert a goto on all edges except the one from src to this label. */
for (e = dest->pred; e ; e = e->pred_next)
{
if (e->src != src)
{
goto_stmt = build1 (GOTO_EXPR, void_type_node, label);
tmp_tree = PENDING_STMT (e);
SET_PENDING_STMT (e, NULL_TREE);
bsi_insert_on_edge_immediate (e, goto_stmt, NULL, &new_bb);
SET_PENDING_STMT (e, tmp_tree);
e->flags = e->flags & ~EDGE_FALLTHRU;
- /* Splitting this edge should never result in a new block. */
- if (new_bb)
- abort ();
}
}
--- 3780,3824 ----
/* Insert a goto on all edges except the one from src to this label. */
+ restart_loop:
for (e = dest->pred; e ; e = e->pred_next)
{
if (e->src != src)
{
+ tmp = bsi_last (e->src);
+ goto_stmt = bsi_stmt (tmp);
+ /* Dont issue a goto if it already goto's this label. See below
+ for how this can happen to a new label. */
+ if (goto_stmt && TREE_CODE (goto_stmt) == GOTO_EXPR
+ && GOTO_DESTINATION (goto_stmt) == label)
+ continue;
+
goto_stmt = build1 (GOTO_EXPR, void_type_node, label);
tmp_tree = PENDING_STMT (e);
SET_PENDING_STMT (e, NULL_TREE);
bsi_insert_on_edge_immediate (e, goto_stmt, NULL, &new_bb);
+
+ /* So splitting this edge *can* result in another basic block
+ if there is a case label nested inside an if construct, for
+ instance. Yes, this is allowed. blah.
+ So this is ugly. The edge may no longer be in the edge list we
+ have been traversing, so we have to start over. First attach any
+ pending insertions to the new edge. This is why we need to check
+ for exisiting GOTO's to our label above. */
+ if (new_bb)
+ {
+ #ifdef ENABLE_CHECKING
+ /* There ought to be exactly one successor to the new block. */
+ if (new_bb->succ == NULL || new_bb->succ->succ_next != NULL)
+ abort();
+ #endif
+ SET_PENDING_STMT (new_bb->succ, tmp_tree);
+ new_bb->succ->flags = new_bb->succ->flags & ~EDGE_FALLTHRU;
+ goto restart_loop;
+ }
SET_PENDING_STMT (e, tmp_tree);
e->flags = e->flags & ~EDGE_FALLTHRU;
}
}