commit 9635244cf232e1919f2695b159b2834e7f29d133
parent aac17c85798b8962ffc038ac3d4b203eb1f4a29b
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Mon, 17 Jan 2022 04:52:14 +0100
gen_data_item: fix generation of tagged globals
Global tagged unions with aggregate constituent types contained
incomplete values of those types.
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/gen.c b/src/gen.c
@@ -3312,7 +3312,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
if (constant->tagged.tag->size != 0) {
item->next = xcalloc(1, sizeof(struct qbe_data_item));
item = item->next;
- gen_data_item(ctx, constant->tagged.value, item);
+ item = gen_data_item(ctx, constant->tagged.value, item);
}
if (constant->tagged.tag->size < type->size - type->align) {
item->next = xcalloc(1, sizeof(struct qbe_data_item));
diff --git a/tests/11-globals.ha b/tests/11-globals.ha
@@ -72,7 +72,15 @@ type foo = (int | uint);
let subtype: foo = 10u;
+let arr_of_tagged_of_tuple: [3]((int, int)|void) = [(1, 2), (3, 4), (5, 6)];
+
fn tagged() void = {
+ assert((arr_of_tagged_of_tuple[0] as (int, int)).0 == 1);
+ assert((arr_of_tagged_of_tuple[0] as (int, int)).1 == 2);
+ assert((arr_of_tagged_of_tuple[1] as (int, int)).0 == 3);
+ assert((arr_of_tagged_of_tuple[1] as (int, int)).1 == 4);
+ assert((arr_of_tagged_of_tuple[2] as (int, int)).0 == 5);
+ assert((arr_of_tagged_of_tuple[2] as (int, int)).1 == 6);
assert(subtype is uint);
// TODO: subset-compat
};
@@ -118,5 +126,6 @@ export fn main() void = {
invariants();
static_binding();
pointers();
+ tagged();
tuplearray();
};