bugfix: field selector on pointers to unions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 28 Sep 2023 21:56:44 +0000 (16:56 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 28 Sep 2023 21:56:44 +0000 (16:56 -0500)
compiler/src/wasm_emit.c

index a361da0a1c552bf706379752b6a9f008d96c7cd9..7afd7c6d83488df36baf704e2acba770155b5e12 100644 (file)
@@ -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);