commit 3520ab2c1510f12b066ab1d1dafcdba6abf2435b
parent 6f196a6391bc882250297db898e70252968ae4f9
Author: Eyal Sawady <ecs@d2evs.net>
Date: Thu, 5 Aug 2021 07:35:17 +0000
gen: fix if with void out
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -538,7 +538,7 @@ gen_expr_if_with(struct gen_context *ctx,
{
struct gen_value gvout = gv_void;
struct qbe_value qvout;
- if (!out) {
+ if (!out && type_dealias(expr->result)->storage != STORAGE_VOID) {
gvout = mktemp(ctx, expr->result, ".%d");
qvout = mkqval(ctx, &gvout);
}
@@ -553,7 +553,7 @@ gen_expr_if_with(struct gen_context *ctx,
push(&ctx->current->body, <rue);
struct gen_value vtrue = gen_expr_with(ctx, expr->_if.true_branch, out);
- if (!out) {
+ if (!out && type_dealias(expr->result)->storage != STORAGE_VOID) {
struct qbe_value qvtrue = mkqval(ctx, &vtrue);
pushi(ctx->current, &qvout, Q_COPY, &qvtrue, NULL);
}
@@ -563,7 +563,7 @@ gen_expr_if_with(struct gen_context *ctx,
if (expr->_if.false_branch) {
struct gen_value vfalse = gen_expr_with(
ctx, expr->_if.false_branch, out);
- if (!out) {
+ if (!out && type_dealias(expr->result)->storage != STORAGE_VOID) {
struct qbe_value qvfalse = mkqval(ctx, &vfalse);
pushi(ctx->current, &qvout, Q_COPY, &qvfalse, NULL);
}
diff --git a/tests/906-if.ha b/tests/906-if.ha
@@ -13,5 +13,7 @@ export fn main() int = {
} else abort();
assert(x.x == 10);
+ if (true) void else void;
+
return 0;
};