harec

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

commit e4e07f37cf2459b327e893b963a29cdd6720d90f
parent 2ffc3196f199e93c00b1bde9f937d7efb587146e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 16 Apr 2021 09:45:41 -0400

gen: alloc: store to pointer after initialization

This fixes an issue where, if an alloc'd object was initialized in a
manner which included its previous value, it would create an recursive
object.

Diffstat:
Msrc/gen.c | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -586,12 +586,10 @@ gen_expr_alloc(struct gen_context *ctx, rtalloc.name = strdup("rt.malloc"); rtalloc.type = &qbe_long; pushi(ctx->current, &ret, Q_CALL, &rtalloc, &size, NULL); - gen_store(ctx, out, &ret); - qval_deref(&ret); + struct qbe_value load = {0}; - gen_loadtemp(ctx, &load, out, - qtype_for_type(ctx, expr->result, false), - type_is_signed(expr->result)); + gen_temp(ctx, &load, &qbe_long, "alloc.storage.%d"); + pushi(ctx->current, &load, Q_COPY, &ret, NULL); struct qbe_statement nulll = {0}, validl = {0}, endl = {0}; struct qbe_value bnull = {0}, bvalid = {0}, bend = {0}; @@ -618,6 +616,7 @@ gen_expr_alloc(struct gen_context *ctx, type_dealias(expr->result)->pointer.referent, false); gen_expression(ctx, expr->alloc.expr, &load); + gen_store(ctx, out, &ret); push(&ctx->current->body, &endl); }