authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-14 23:37:04-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:37-08:00
loga7bd1a631b9dd5b1221fdc0f3e4b299bda18138c
treeed831fe0304bc647614f6ea5aba7582edea85559
parent204e689bdb74c5020a9201d20db976251f122250

wasm codegen: fix mistaking extern data as function


2 files changed, 15 insertions(+), 1 deletions(-)

src/InternPool.zig+14
...@@ -616,6 +616,20 @@ pub const Nav = struct {...@@ -616,6 +616,20 @@ pub const Nav = struct {
616 };616 };
617 }617 }
618618
619 pub fn isFn(nav: Nav, ip: *const InternPool) bool {
620 return switch (nav.status) {
621 .unresolved => unreachable,
622 .type_resolved => |r| {
623 const tag = ip.zigTypeTagOrPoison(r.type) catch unreachable;
624 return tag == .@"fn";
625 },
626 .fully_resolved => |r| {
627 const tag = ip.zigTypeTagOrPoison(ip.typeOf(r.val)) catch unreachable;
628 return tag == .@"fn";
629 },
630 };
631 }
632
619 /// If this returns `true`, then a pointer to this `Nav` might actually be encoded as a pointer633 /// If this returns `true`, then a pointer to this `Nav` might actually be encoded as a pointer
620 /// to some other `Nav` due to an extern definition or extern alias (see #21027).634 /// to some other `Nav` due to an extern definition or extern alias (see #21027).
621 /// This query is valid on `Nav`s for whom only the type is resolved.635 /// This query is valid on `Nav`s for whom only the type is resolved.
src/arch/wasm/CodeGen.zig+1-1
...@@ -1022,7 +1022,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {...@@ -1022,7 +1022,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
1022 const comp = wasm.base.comp;1022 const comp = wasm.base.comp;
1023 const zcu = comp.zcu.?;1023 const zcu = comp.zcu.?;
1024 const ip = &zcu.intern_pool;1024 const ip = &zcu.intern_pool;
1025 if (ip.getNav(nav_ref.nav_index).isExternOrFn(ip)) {1025 if (ip.getNav(nav_ref.nav_index).isFn(ip)) {
1026 assert(nav_ref.offset == 0);1026 assert(nav_ref.offset == 0);
1027 const gop = try wasm.zcu_indirect_function_set.getOrPut(comp.gpa, nav_ref.nav_index);1027 const gop = try wasm.zcu_indirect_function_set.getOrPut(comp.gpa, nav_ref.nav_index);
1028 if (!gop.found_existing) gop.value_ptr.* = {};1028 if (!gop.found_existing) gop.value_ptr.* = {};