[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Wed Jun 15 15:44:38 PDT 2005
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.100 -> 1.101
---
Log message:
Rename to llvm_expand_exit_something -> llvm_expand_break_something, as it
inserts code for the 'break' statement.
Fix PR580: http://llvm.cs.uiuc.edu/PR580 by always emitting a new label after emitting an unconditional goto.
This fixes PR580: http://llvm.cs.uiuc.edu/PR580 , including cases where the continue is replaced with a
break or a goto.
Testcase here: Regression/CFrontend/2005-06-15-ExpandGotoInternalProblem.c
---
Diffs of the changes: (+29 -7)
llvm-expand.c | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.100 llvm-gcc/gcc/llvm-expand.c:1.101
--- llvm-gcc/gcc/llvm-expand.c:1.100 Tue Jun 14 16:40:55 2005
+++ llvm-gcc/gcc/llvm-expand.c Wed Jun 15 17:44:27 2005
@@ -1566,7 +1566,7 @@
/* Generate LLVM for the start of an if-then. COND is the expression whose
truth should be tested.
- If EXITFLAG is nonzero, this conditional is visible to `exit_something'. */
+ If EXITFLAG is nonzero, this conditional is visible to `break_something'. */
static void llvm_expand_start_cond (llvm_function *Fn, tree cond, int exitflag,
int has_else) {
@@ -1825,7 +1825,7 @@
}
/* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
- loop should be exited by `exit_something'. This is a loop for which
+ loop should be exited by `break_something'. This is a loop for which
`expand_continue' will jump to the top of the loop.
Make an entry on loop_stack to record the labels associated with
@@ -1917,6 +1917,12 @@
whichloop->x.loop.ContinueFound = 1;
llvm_expand_goto_internal(Fn, whichloop->x.loop.continue_label, 1, 0);
+
+ /* Start a new block so that if statements are emitted after the continue,
+ * that they will have the correct "current block".
+ */
+ llvm_emit_label(Fn, llvm_basicblock_new("dead_block_after_continue"));
+
return 1;
}
@@ -1992,12 +1998,17 @@
If not currently inside anything that can be exited,
return 0 and do nothing; caller will print an error message. */
-static int llvm_expand_exit_something(llvm_function *Fn) {
+static int llvm_expand_break_something(llvm_function *Fn) {
llvm_nesting *n;
for (n = Fn->ExpandInfo->InnermostScope; n; n = n->all)
if (n->exit_block) {
n->BreakFound = 1;
llvm_expand_goto_internal(Fn, n->exit_block, 1, 0);
+
+ /* Start a new block so that if statements are emitted after the break,
+ * that they will have the correct "current block".
+ */
+ llvm_emit_label(Fn, llvm_basicblock_new("dead_block_after_break"));
return 1;
}
@@ -2010,8 +2021,8 @@
case-labels that are seen and to record the labels generated for the
statement.
- EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
- Otherwise, this construct is transparent for `exit_something'.
+ EXIT_FLAG is nonzero if `break_something' should exit this case stmt.
+ Otherwise, this construct is transparent for `break_something'.
EXPR is the index-expression to be dispatched on.
*/
@@ -2208,14 +2219,25 @@
append_inst(Fn, create_store_inst(V, Fn->ExpandInfo->IndirectGotoValue, 0));
/* FIXME: This is HORRIBLY INCORRECT in the presence of exception handlers.
- * There should be one collector block per cleanup level!
+ * There should be one collector block per cleanup level! Note that
+ * standard GCC gets this wrong as well.
*/
llvm_expand_goto_internal(Fn, Fn->ExpandInfo->IndirectGotoBlock, 1, 0);
+
+ /* Start a new block so that if statements are emitted after the goto, that
+ * they will have the correct "current block".
+ */
+ llvm_emit_label(Fn, llvm_basicblock_new("dead_block_after_goto"));
return;
}
TREE_USED(dest) = 1;
llvm_expand_goto_internal(Fn, getLabelDeclBlock(dest), 1, 0);
+
+ /* Start a new block so that if statements are emitted after the goto, that
+ * they will have the correct "current block".
+ */
+ llvm_emit_label(Fn, llvm_basicblock_new("dead_block_after_goto"));
}
/* Generate LLVM code for a RETURN_STMT */
@@ -2766,7 +2788,7 @@
break;
case BREAK_STMT:
- if (!llvm_expand_exit_something(Fn))
+ if (!llvm_expand_break_something(Fn))
error ("break statement not within loop or switch");
break;
More information about the llvm-commits
mailing list