cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit b50da146cd150937f9c2b7d7813a307de411e298
parent 3cc28c8428306a66350ef3722d45ed8c49bc6f15
Author: Michael Forney <mforney@mforney.org>
Date:   Fri,  5 Jul 2019 12:51:34 -0700

stmt: Fix conversion of controlling expression to bool

In d875bf74, I accidentally converted the increment expression to bool
rather than the controlling expression.

Whoops, I should check the updated test case IL more carefully next time.

Diffstat:
Mstmt.c | 4++--
Mtest/for-loop.qbe | 14+++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/stmt.c b/stmt.c @@ -220,13 +220,13 @@ stmt(struct func *f, struct scope *s) funclabel(f, label[0]); if (tok.kind != TSEMICOLON) { - e = expr(s); + e = exprconvert(expr(s), &typebool); v = funcexpr(f, e); funcjnz(f, v, label[1], label[3]); delexpr(e); } expect(TSEMICOLON, NULL); - e = tok.kind == TRPAREN ? NULL : exprconvert(expr(s), &typebool); + e = tok.kind == TRPAREN ? NULL : expr(s); expect(TRPAREN, NULL); funclabel(f, label[1]); diff --git a/test/for-loop.qbe b/test/for-loop.qbe @@ -7,15 +7,15 @@ function $f() { @for_cond.3 %.2 =w loadsw %.1 %.3 =w csltw %.2, 10 - jnz %.3, @for_body.4, @for_join.6 + %.4 =w cnew %.3, 0 + jnz %.4, @for_body.4, @for_join.6 @for_body.4 - %.4 =w loadsw %.1 - call $g(w %.4) -@for_cont.5 %.5 =w loadsw %.1 - %.6 =w add %.5, 1 - storew %.6, %.1 - %.7 =w cnew %.6, 0 + call $g(w %.5) +@for_cont.5 + %.6 =w loadsw %.1 + %.7 =w add %.6, 1 + storew %.7, %.1 jmp @for_cond.3 @for_join.6 ret