harec

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

commit c28716b1013bd745fb156681d0618c859e6fe7e5
parent 5ba69ba61fac1df66dc6580b23058a7503ffbc42
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 12 Mar 2021 09:17:52 -0500

gen: fix storage of arrays

Diffstat:
Msrc/gen.c | 3+++
Msrc/qtype.c | 14++++++++------
2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -1331,6 +1331,9 @@ gen_expr_cast(struct gen_context *ctx, qval_deref(&in); } else { gen_temp(ctx, &in, qtype_for_type(ctx, from, false), "cast.in.%d"); + if (type_is_aggregate(expr->cast.value->result)) { + qval_address(&in); + } } gen_expression(ctx, expr->cast.value, &in); diff --git a/src/qtype.c b/src/qtype.c @@ -162,12 +162,9 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type) } } - switch (type->storage) { - // Special cases - case STORAGE_ARRAY: + if (type->storage == STORAGE_ARRAY && type->array.length == SIZE_UNDEFINED) { + // Special case return &qbe_long; - default: - break; } int n = snprintf(NULL, 0, "type.%zd", ctx->id); @@ -186,6 +183,12 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type) struct qbe_field *field = &def->type.fields; switch (type->storage) { + case STORAGE_ARRAY: + assert(type->array.length != SIZE_UNDEFINED); + def->type.align = type->align; + field->type = qtype_for_type(ctx, type->array.members, true); + field->count = type->array.length; + break; case STORAGE_STRING: field->type = &qbe_long; // XXX: ARCH field->count = 3; @@ -252,7 +255,6 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type) } break; case STORAGE_ENUM: - case STORAGE_ARRAY: case STORAGE_ALIAS: case STORAGE_CHAR: case STORAGE_I8: