wasm codegen: fix mistaking extern data as function

This commit is contained in:
Andrew Kelley
2025-01-14 23:37:04 -08:00
parent 204e689bdb
commit a7bd1a631b
2 changed files with 15 additions and 1 deletions

View File

@@ -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.

View File

@@ -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.* = {};