harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c790744abb4f02f31044fe11bd4b2eebf34bc81b
parent 7005c57f980d29b6295adcce20ebfe44876f3097
Author: Armin Weigl <tb46305@gmail.com>
Date:   Fri, 31 Dec 2021 23:58:30 +0100

gen_expr_unarithm: handle booleans >1

According to the spec any non-zero value should be treated as true

Signed-off-by: Armin Weigl <tb46305@gmail.com>

Diffstat:
Msrc/gen.c | 8++++----
Mtests/29-unarithm.ha | 1+
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -2711,15 +2711,15 @@ gen_expr_unarithm(struct gen_context *ctx, val = gen_expr(ctx, operand); temp = mktemp(ctx, operand->result, ".%d"); qval = mkqval(ctx, &val), qtmp = mkqval(ctx, &temp); - struct qbe_value one = constl(1); - pushi(ctx->current, &qtmp, Q_XOR, &qval, &one, NULL); + struct qbe_value zerow = constw(0); + pushi(ctx->current, &qtmp, Q_CEQW, &qval, &zerow, NULL); return temp; case UN_MINUS: val = gen_expr(ctx, operand); temp = mktemp(ctx, operand->result, ".%d"); qval = mkqval(ctx, &val), qtmp = mkqval(ctx, &temp); - struct qbe_value zero = constl(0); - pushi(ctx->current, &qtmp, Q_SUB, &zero, &qval, NULL); + struct qbe_value zerol = constl(0); + pushi(ctx->current, &qtmp, Q_SUB, &zerol, &qval, NULL); return temp; case UN_PLUS: return gen_expr(ctx, operand); diff --git a/tests/29-unarithm.ha b/tests/29-unarithm.ha @@ -1,6 +1,7 @@ type abool = bool; fn lnot() void = { + assert((!*(&2: *bool))==false); assert(!(false: abool)); };