From a6bebd23cee425311c42609a184e1be749970c76 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 28 Sep 2023 16:56:44 -0500 Subject: [PATCH] bugfix: field selector on pointers to unions --- compiler/src/wasm_emit.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index a361da0a..7afd7c6d 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -3584,8 +3584,15 @@ EMIT_FUNC(expression, AstTyped* expr) { emit_stack_address(mod, &code, intermediate_local + type_alignment_of(field->type), field->token); WIL(NULL, WI_LOCAL_GET, source_base_ptr); - WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type)); + + if (type_is_pointer(field->expr->type)) { + WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type->Pointer.elem)); + } else { + WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type)); + } + WI(NULL, WI_I32_ADD); + WIL(NULL, WI_I32_CONST, type_size_of(field->type->Union.variants_ordered[1]->type)); emit_wasm_copy(mod, &code, NULL); -- 2.25.1