authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-06-15 19:30:00+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-06-16 17:16:56+02:00
loge3db210cf1007f87930c97c072c54b2fb8ae0b8c
treec11e1e47dbf59e745aef594a9e446f100b839efe
parent1cfad29f10a557df986fc940dcce7620bbd5d4d9
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 12 insertions(+), 5 deletions(-)

src/arch/wasm/CodeGen.zig+11
......@@ -3008,6 +3008,17 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Ind
30083008 }
30093009
30103010 const decl = mod.declPtr(decl_index);
3011 // check if decl is an alias to a function, in which case we
3012 // want to lower the actual decl, rather than the alias itself.
3013 if (decl.val.getFunction(mod)) |func_val| {
3014 if (func_val.owner_decl != decl_index) {
3015 return func.lowerDeclRefValue(tv, func_val.owner_decl, offset);
3016 }
3017 } else if (decl.val.getExternFunc(mod)) |func_val| {
3018 if (func_val.decl != decl_index) {
3019 return func.lowerDeclRefValue(tv, func_val.decl, offset);
3020 }
3021 }
30113022 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
30123023 return WValue{ .imm32 = 0xaaaaaaaa };
30133024 }
test/behavior.zig+1-5
......@@ -158,6 +158,7 @@ test {
158158 _ = @import("behavior/enum.zig");
159159 _ = @import("behavior/error.zig");
160160 _ = @import("behavior/eval.zig");
161 _ = @import("behavior/export_self_referential_type_info.zig");
161162 _ = @import("behavior/field_parent_ptr.zig");
162163 _ = @import("behavior/floatop.zig");
163164 _ = @import("behavior/fn.zig");
......@@ -241,7 +242,6 @@ test {
241242 if (builtin.zig_backend != .stage2_arm and
242243 builtin.zig_backend != .stage2_x86_64 and
243244 builtin.zig_backend != .stage2_aarch64 and
244 builtin.zig_backend != .stage2_wasm and
245245 builtin.zig_backend != .stage2_c and
246246 builtin.zig_backend != .stage2_spirv64)
247247 {
......@@ -250,8 +250,4 @@ test {
250250 _ = @import("behavior/bugs/14198.zig");
251251 _ = @import("behavior/export.zig");
252252 }
253
254 if (builtin.zig_backend != .stage2_wasm) {
255 _ = @import("behavior/export_self_referential_type_info.zig");
256 }
257253}