aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-06-15 19:30:00 +0200
committerLuuk de Gram <luuk@degram.dev>2023-06-16 17:16:56 +0200
commite3db210cf1007f87930c97c072c54b2fb8ae0b8c (patch)
treec11e1e47dbf59e745aef594a9e446f100b839efe /src
parent1cfad29f10a557df986fc940dcce7620bbd5d4d9 (diff)
downloadzig-e3db210cf1007f87930c97c072c54b2fb8ae0b8c.tar.gz
zig-e3db210cf1007f87930c97c072c54b2fb8ae0b8c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/arch/wasm/CodeGen.zig11
1 files changed, 11 insertions, 0 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 };
}