From a7bd1a631b9dd5b1221fdc0f3e4b299bda18138c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 14 Jan 2025 23:37:04 -0800 Subject: [PATCH] wasm codegen: fix mistaking extern data as function --- src/InternPool.zig | 14 ++++++++++++++ src/arch/wasm/CodeGen.zig | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index 9c91dfae6a..30a0dd087c 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -616,6 +616,20 @@ pub const Nav = struct { }; } + pub fn isFn(nav: Nav, ip: *const InternPool) bool { + return switch (nav.status) { + .unresolved => unreachable, + .type_resolved => |r| { + const tag = ip.zigTypeTagOrPoison(r.type) catch unreachable; + return tag == .@"fn"; + }, + .fully_resolved => |r| { + const tag = ip.zigTypeTagOrPoison(ip.typeOf(r.val)) catch unreachable; + return tag == .@"fn"; + }, + }; + } + /// If this returns `true`, then a pointer to this `Nav` might actually be encoded as a pointer /// to some other `Nav` due to an extern definition or extern alias (see #21027). /// This query is valid on `Nav`s for whom only the type is resolved. diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 91bb00e61e..90c5521695 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1022,7 +1022,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void { const comp = wasm.base.comp; const zcu = comp.zcu.?; const ip = &zcu.intern_pool; - if (ip.getNav(nav_ref.nav_index).isExternOrFn(ip)) { + if (ip.getNav(nav_ref.nav_index).isFn(ip)) { assert(nav_ref.offset == 0); const gop = try wasm.zcu_indirect_function_set.getOrPut(comp.gpa, nav_ref.nav_index); if (!gop.found_existing) gop.value_ptr.* = {};