harec

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

commit d7cb279b5594ad03e1830f743e92a4f14c8a95d1
parent e4e07f37cf2459b327e893b963a29cdd6720d90f
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 16 Apr 2021 09:54:19 -0400

gen: to_tagged: set tag after gen_expr

Fixes #377

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

diff --git a/src/gen.c b/src/gen.c @@ -1200,19 +1200,11 @@ gen_cast_to_tagged(struct gen_context *ctx, pushc(ctx->current, "to_tagged; valid subtype"); assert(subtype->id == from->id); // Lowered by check - if (out) { - char *type = gen_typename(subtype); - pushc(ctx->current, "%u => %s", subtype->id, type); - free(type); - constw(&tag, subtype->id); - pushi(ctx->current, &ptr, Q_COPY, out, NULL); - pushi(ctx->current, NULL, Q_STOREW, &tag, &ptr, NULL); - } - struct qbe_value *storage; if (expr->cast.value->result->size == 0) { storage = NULL; } else if (out) { + pushi(ctx->current, &ptr, Q_COPY, out, NULL); pushi(ctx->current, &ptr, Q_ADD, &ptr, &offs, NULL); ptr.type = qtype_for_type(ctx, expr->cast.value->result, false); qval_deref(&ptr); @@ -1222,6 +1214,16 @@ gen_cast_to_tagged(struct gen_context *ctx, } gen_expression(ctx, expr->cast.value, storage); + + if (out) { + char *type = gen_typename(subtype); + pushc(ctx->current, "%u => %s", subtype->id, type); + free(type); + constw(&tag, subtype->id); + ptr.type = &qbe_long; + pushi(ctx->current, &ptr, Q_COPY, out, NULL); + pushi(ctx->current, NULL, Q_STOREW, &tag, &ptr, NULL); + } } static void