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 | |
| 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')
| -rw-r--r-- | src/Makefile | 3 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 1 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 29 | ||||
| -rw-r--r-- | src/test/run-pass/while-and-do-while.rs | 14 |
4 files changed, 35 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile index 8406d307..33cb0a0d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -447,8 +447,9 @@ TEST_XFAILS_X86 := $(TASK_XFAILS) \ test/run-pass/mlist-cycle.rs \ test/run-pass/obj-as.rs \ test/run-pass/task-comm.rs \ - test/run-pass/vec-slice.rs \ test/run-pass/task-comm-3.rs \ + test/run-pass/vec-slice.rs \ + test/run-pass/while-and-do-while.rs \ test/run-fail/task-comm-14.rs \ test/compile-fail/bad-recv.rs \ test/compile-fail/bad-send.rs \ diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 97742a18..d42f7b45 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -636,6 +636,7 @@ impure fn parse_do_while_expr(parser p) -> @ast.expr { expect (p, token.LPAREN); auto cond = parse_expr(p); expect(p, token.RPAREN); + expect(p, token.SEMI); hi = cond.span; ret @spanned(lo, hi, ast.expr_do_while(body, cond, ast.ann_none)); } 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); diff --git a/src/test/run-pass/while-and-do-while.rs b/src/test/run-pass/while-and-do-while.rs new file mode 100644 index 00000000..ebf78099 --- /dev/null +++ b/src/test/run-pass/while-and-do-while.rs @@ -0,0 +1,14 @@ +fn main() { + let int x = 10; + let int y = 0; + while(y < x) { + log y; + log "hello"; + y = y + 1; + } + do { + log "goodbye"; + x = x - 1; + log x; + } while (x > 0); +}
\ No newline at end of file |