diff options
| author | Graydon Hoare <[email protected]> | 2010-11-04 07:55:33 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-11-04 07:55:33 -0700 |
| commit | 16faef2218ec5c3621079f04e6b093a5bb1b44c2 (patch) | |
| tree | 9278653ee3a42409e7f27ab5c52282ff1512d500 /src/comp/middle/trans.rs | |
| parent | rustboot: When resolving recursively, build up error messages recursively as ... (diff) | |
| download | rust-16faef2218ec5c3621079f04e6b093a5bb1b44c2.tar.xz rust-16faef2218ec5c3621079f04e6b093a5bb1b44c2.zip | |
Fix buggy while and do-while translation in rustc. Add test.
Diffstat (limited to 'src/comp/middle/trans.rs')
| -rw-r--r-- | src/comp/middle/trans.rs | 29 |
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); |