Skip to content

Commit 3d738e9

Browse files
committed
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).
1 parent 9432626 commit 3d738e9

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

Diff for: src/comp/middle/trans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5488,7 +5488,7 @@ fn trans_break_cont(@block_ctxt cx, bool to_end) -> result {
54885488
}
54895489
}
54905490
}
5491-
ret res(bcx, C_nil());
5491+
ret res(new_sub_block_ctxt(bcx, "unreachable"), C_nil());
54925492
}
54935493
case (_) {
54945494
alt (cleanup_cx.parent) {
@@ -5544,7 +5544,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
55445544
}
55455545

55465546
bcx.build.RetVoid();
5547-
ret res(bcx, C_nil());
5547+
ret res(new_sub_block_ctxt(bcx, "unreachable"), C_nil());
55485548
}
55495549

55505550
fn trans_be(@block_ctxt cx, @ast.expr e) -> result {

Diff for: src/test/run-pass/artificial-block.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
// xfail-stage0
2-
// xfail-stage1
3-
// xfail-stage2
4-
// xfail-stage1
5-
// xfail-stage2
62
fn f() -> int {
73
{ ret 3; }
84
}

0 commit comments

Comments
 (0)