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...@@ -3008,6 +3008,17 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Ind
3008 }3008 }
30093009
3010 const decl = mod.declPtr(decl_index);3010 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 }
3011 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {3022 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
3012 return WValue{ .imm32 = 0xaaaaaaaa };3023 return WValue{ .imm32 = 0xaaaaaaaa };
3013 }3024 }
test/behavior.zig+1-5
...@@ -158,6 +158,7 @@ test {...@@ -158,6 +158,7 @@ test {
158 _ = @import("behavior/enum.zig");158 _ = @import("behavior/enum.zig");
159 _ = @import("behavior/error.zig");159 _ = @import("behavior/error.zig");
160 _ = @import("behavior/eval.zig");160 _ = @import("behavior/eval.zig");
161 _ = @import("behavior/export_self_referential_type_info.zig");
161 _ = @import("behavior/field_parent_ptr.zig");162 _ = @import("behavior/field_parent_ptr.zig");
162 _ = @import("behavior/floatop.zig");163 _ = @import("behavior/floatop.zig");
163 _ = @import("behavior/fn.zig");164 _ = @import("behavior/fn.zig");
...@@ -241,7 +242,6 @@ test {...@@ -241,7 +242,6 @@ test {
241 if (builtin.zig_backend != .stage2_arm and242 if (builtin.zig_backend != .stage2_arm and
242 builtin.zig_backend != .stage2_x86_64 and243 builtin.zig_backend != .stage2_x86_64 and
243 builtin.zig_backend != .stage2_aarch64 and244 builtin.zig_backend != .stage2_aarch64 and
244 builtin.zig_backend != .stage2_wasm and
245 builtin.zig_backend != .stage2_c and245 builtin.zig_backend != .stage2_c and
246 builtin.zig_backend != .stage2_spirv64)246 builtin.zig_backend != .stage2_spirv64)
247 {247 {
...@@ -250,8 +250,4 @@ test {...@@ -250,8 +250,4 @@ test {
250 _ = @import("behavior/bugs/14198.zig");250 _ = @import("behavior/bugs/14198.zig");
251 _ = @import("behavior/export.zig");251 _ = @import("behavior/export.zig");
252 }252 }
253
254 if (builtin.zig_backend != .stage2_wasm) {
255 _ = @import("behavior/export_self_referential_type_info.zig");
256 }
257}253}