rustc: Fix memory leak in do-while loop

Issue #1257
This commit is contained in:
Haitao Li 2011-12-05 00:33:25 +08:00
parent 9711596bec
commit 96b0881a68
2 changed files with 13 additions and 2 deletions

View file

@ -2844,8 +2844,11 @@ fn trans_do_while(cx: @block_ctxt, body: ast::blk, cond: @ast::expr) ->
new_loop_scope_block_ctxt(cx, option::none::<@block_ctxt>, next_cx,
"do-while loop body");
let body_end = trans_block(body_cx, body);
let cond_res = trans_temp_expr(body_end, cond);
CondBr(cond_res.bcx, cond_res.val, body_cx.llbb, next_cx.llbb);
let cond_cx = new_scope_block_ctxt(body_cx, "do-while cond");
Br(body_end, 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);
Br(cx, body_cx.llbb);
ret next_cx;
}

View file

@ -0,0 +1,8 @@
fn main () {
let line = "";
let i = 0;
do {
line = if i == 9 { "exit" } else { "notexit" };
i += 1;
} while line != "exit";
}