Skip to content

Commit aeb445b

Browse files
committed
rustc: Don't make the while loop body's basic block a child of the condition
As a child of the condition, when the body encounters a ret or break it incorrectly re-runs the cleanups of the condition.
1 parent b87cdd8 commit aeb445b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/rustc/middle/trans/base.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2001,10 +2001,12 @@ fn trans_for(cx: block, local: @ast::local, seq: @ast::expr,
20012001
fn trans_while(cx: block, cond: @ast::expr, body: ast::blk)
20022002
-> block {
20032003
let next_cx = sub_block(cx, "while next");
2004-
let cond_cx = loop_scope_block(cx, cont_self, next_cx,
2005-
"while cond", body.span);
2006-
let body_cx = scope_block(cond_cx, "while loop body");
2007-
Br(cx, cond_cx.llbb);
2004+
let loop_cx = loop_scope_block(cx, cont_self, next_cx,
2005+
"while loop", body.span);
2006+
let cond_cx = scope_block(loop_cx, "while loop cond");
2007+
let body_cx = scope_block(loop_cx, "while loop body");
2008+
Br(cx, loop_cx.llbb);
2009+
Br(loop_cx, cond_cx.llbb);
20082010
let cond_res = trans_temp_expr(cond_cx, cond);
20092011
let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
20102012
CondBr(cond_bcx, cond_res.val, body_cx.llbb, next_cx.llbb);

src/test/run-pass/issue-1974.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Issue 1974
2+
// Don't double free the condition allocation
3+
fn main() {
4+
let s = "hej";
5+
while s != "" {
6+
ret;
7+
}
8+
}

0 commit comments

Comments
 (0)