Skip to content

Commit

Permalink
rustc: Don't make the while loop body's basic block a child of the co…
Browse files Browse the repository at this point in the history
…ndition

As a child of the condition, when the body encounters a ret or break it
incorrectly re-runs the cleanups of the condition.
  • Loading branch information
brson committed Mar 14, 2012
1 parent b87cdd8 commit aeb445b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/rustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,10 +2001,12 @@ fn trans_for(cx: block, local: @ast::local, seq: @ast::expr,
fn trans_while(cx: block, cond: @ast::expr, body: ast::blk)
-> block {
let next_cx = sub_block(cx, "while next");
let cond_cx = loop_scope_block(cx, cont_self, next_cx,
"while cond", body.span);
let body_cx = scope_block(cond_cx, "while loop body");
Br(cx, cond_cx.llbb);
let loop_cx = loop_scope_block(cx, cont_self, next_cx,
"while loop", body.span);
let cond_cx = scope_block(loop_cx, "while loop cond");
let body_cx = scope_block(loop_cx, "while loop body");
Br(cx, loop_cx.llbb);
Br(loop_cx, cond_cx.llbb);
let cond_res = trans_temp_expr(cond_cx, cond);
let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
CondBr(cond_bcx, cond_res.val, body_cx.llbb, next_cx.llbb);
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-pass/issue-1974.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Issue 1974
// Don't double free the condition allocation
fn main() {
let s = "hej";
while s != "" {
ret;
}
}

0 comments on commit aeb445b

Please sign in to comment.