Return a fresh, unreachable context after ret, break, and cont

This ensures we don't get compile errors on unreachable code (see
test/run-pass/artificial-block.rs for an example of sane code that
wasn't compiling). In the future, we might want to warn about
non-trivial code appearing in an unreachable context, and/or avoid
generating unreachable code altogether (though I'm sure LLVM will weed
it out as well).
This commit is contained in:
Marijn Haverbeke 2011-05-05 15:30:21 +02:00
parent 9432626b68
commit 3d738e9e06
2 changed files with 2 additions and 6 deletions

View File

@ -5488,7 +5488,7 @@ fn trans_break_cont(@block_ctxt cx, bool to_end) -> result {
}
}
}
ret res(bcx, C_nil());
ret res(new_sub_block_ctxt(bcx, "unreachable"), C_nil());
}
case (_) {
alt (cleanup_cx.parent) {
@ -5544,7 +5544,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
}
bcx.build.RetVoid();
ret res(bcx, C_nil());
ret res(new_sub_block_ctxt(bcx, "unreachable"), C_nil());
}
fn trans_be(@block_ctxt cx, @ast.expr e) -> result {

View File

@ -1,8 +1,4 @@
// xfail-stage0
// xfail-stage1
// xfail-stage2
// xfail-stage1
// xfail-stage2
fn f() -> int {
{ ret 3; }
}