aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-04 07:55:33 -0700
committerGraydon Hoare <[email protected]>2010-11-04 07:55:33 -0700
commit16faef2218ec5c3621079f04e6b093a5bb1b44c2 (patch)
tree9278653ee3a42409e7f27ab5c52282ff1512d500 /src/comp/middle
parentrustboot: When resolving recursively, build up error messages recursively as ... (diff)
downloadrust-16faef2218ec5c3621079f04e6b093a5bb1b44c2.tar.xz
rust-16faef2218ec5c3621079f04e6b093a5bb1b44c2.zip
Fix buggy while and do-while translation in rustc. Add test.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/trans.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index c5374212..1783925e 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -660,13 +660,15 @@ impure fn trans_while(@block_ctxt cx, &ast.expr cond,
auto body_cx = new_empty_block_ctxt(cx.fcx);
auto next_cx = new_extension_block_ctxt(cx);
- cx.build.Br(cond_cx.llbb);
- auto cond_res = trans_expr(cond_cx, cond);
- cond_cx.build.CondBr(cond_res.val,
- body_cx.llbb,
- next_cx.llbb);
auto body_res = trans_block(body_cx, body);
- body_cx.build.Br(cond_cx.llbb);
+ auto cond_res = trans_expr(cond_cx, cond);
+
+ body_res.bcx.build.Br(cond_cx.llbb);
+ cond_res.bcx.build.CondBr(cond_res.val,
+ body_cx.llbb,
+ next_cx.llbb);
+
+ cx.build.Br(cond_cx.llbb);
ret res(next_cx, C_nil());
}
@@ -676,12 +678,13 @@ impure fn trans_do_while(@block_ctxt cx, &ast.block body,
auto body_cx = new_empty_block_ctxt(cx.fcx);
auto next_cx = new_extension_block_ctxt(cx);
- cx.build.Br(body_cx.llbb);
auto body_res = trans_block(body_cx, body);
- auto cond_res = trans_expr(body_cx, cond);
- body_cx.build.CondBr(cond_res.val,
- body_cx.llbb,
- next_cx.llbb);
+ auto cond_res = trans_expr(body_res.bcx, cond);
+
+ cond_res.bcx.build.CondBr(cond_res.val,
+ body_cx.llbb,
+ next_cx.llbb);
+ cx.build.Br(body_cx.llbb);
ret res(next_cx, body_res.val);
}
@@ -759,6 +762,10 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
ret trans_while(cx, *cond, body);
}
+ case (ast.expr_do_while(?body, ?cond, _)) {
+ ret trans_do_while(cx, body, *cond);
+ }
+
case (ast.expr_block(?blk, _)) {
auto sub_cx = new_empty_block_ctxt(cx.fcx);
auto next_cx = new_extension_block_ctxt(cx);