From e3db210cf1007f87930c97c072c54b2fb8ae0b8c Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Thu, 15 Jun 2023 19:30:00 +0200 Subject: [PATCH] wasm: support calling alias'd function pointers When lowering a decl value we verify whether its owner decl index equals to the decl index of the decl being lowered. When this is not the case, we are lowering an alias. So instead, we will now lower the owner decl instead and call its symbol to ensure its type is being correctly generated. --- src/arch/wasm/CodeGen.zig | 11 +++++++++++ test/behavior.zig | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 9a19ca439c..aa44dc2bc8 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3008,6 +3008,17 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Ind } const decl = mod.declPtr(decl_index); + // check if decl is an alias to a function, in which case we + // want to lower the actual decl, rather than the alias itself. + if (decl.val.getFunction(mod)) |func_val| { + if (func_val.owner_decl != decl_index) { + return func.lowerDeclRefValue(tv, func_val.owner_decl, offset); + } + } else if (decl.val.getExternFunc(mod)) |func_val| { + if (func_val.decl != decl_index) { + return func.lowerDeclRefValue(tv, func_val.decl, offset); + } + } if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) { return WValue{ .imm32 = 0xaaaaaaaa }; } diff --git a/test/behavior.zig b/test/behavior.zig index bdc3f30ede..017b5b4824 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -158,6 +158,7 @@ test { _ = @import("behavior/enum.zig"); _ = @import("behavior/error.zig"); _ = @import("behavior/eval.zig"); + _ = @import("behavior/export_self_referential_type_info.zig"); _ = @import("behavior/field_parent_ptr.zig"); _ = @import("behavior/floatop.zig"); _ = @import("behavior/fn.zig"); @@ -241,7 +242,6 @@ test { if (builtin.zig_backend != .stage2_arm and builtin.zig_backend != .stage2_x86_64 and builtin.zig_backend != .stage2_aarch64 and - builtin.zig_backend != .stage2_wasm and builtin.zig_backend != .stage2_c and builtin.zig_backend != .stage2_spirv64) { @@ -250,8 +250,4 @@ test { _ = @import("behavior/bugs/14198.zig"); _ = @import("behavior/export.zig"); } - - if (builtin.zig_backend != .stage2_wasm) { - _ = @import("behavior/export_self_referential_type_info.zig"); - } }