commit f0ccdf7ae3e0edae15260cc27e0d24284a46b9c3
parent 5447294cb9a3637ddf980f675986e2837de89466
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 30 Jan 2021 18:21:36 -0500
gen: fix storing void to tagged union
Diffstat:
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/dump.c b/src/dump.c
@@ -353,7 +353,8 @@ dump_expr(const struct expression *expr, int depth)
fprintf(stderr, "measure");
break;
case EXPR_RETURN:
- fprintf(stderr, "return");
+ fprintf(stderr, "return ");
+ dump_expr(expr->_return.value, depth + 1);
break;
case EXPR_SLICE:
fprintf(stderr, "slice");
diff --git a/src/gen.c b/src/gen.c
@@ -924,15 +924,23 @@ gen_cast_to_tagged(struct gen_context *ctx,
gen_expression(ctx, expr->cast.value, &ptr);
gen_copy(ctx, out, &ptr);
return;
- }
+ }
constw(&tag, expr->cast.value->result->id);
pushi(ctx->current, &ptr, Q_COPY, out, NULL);
pushi(ctx->current, NULL, Q_STOREW, &tag, &ptr, NULL);
- pushi(ctx->current, &ptr, Q_ADD, &ptr, &offs, NULL);
- ptr.type = qtype_for_type(ctx, expr->cast.value->result, false);
- ptr.indirect = !type_is_aggregate(expr->cast.value->result);
- gen_expression(ctx, expr->cast.value, &ptr);
+
+ struct qbe_value *storage;
+ if (expr->cast.value->result->size == 0) {
+ storage = NULL;
+ } else {
+ pushi(ctx->current, &ptr, Q_ADD, &ptr, &offs, NULL);
+ ptr.type = qtype_for_type(ctx, expr->cast.value->result, false);
+ ptr.indirect = !type_is_aggregate(expr->cast.value->result);
+ storage = &ptr;
+ }
+
+ gen_expression(ctx, expr->cast.value, storage);
}
static void