zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c64755fb2f3178b4f593ef9f2cb54beef03af36f (tree)
parent 978f7fb1ff1cdb36f48b774516aa09ab6a1dfbc0
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Sat, 28 Feb 2026 11:58:23 +0000

Type: fix assertion failure

Diffstat:
Msrc/Type.zig | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/Type.zig b/src/Type.zig @@ -3094,7 +3094,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool if (ty.isSlice(zcu)) return false; const child_ty = ty.childType(zcu); if (child_ty.zigTypeTag(zcu) == .@"fn") { - return ty.isConstPtr(zcu) and child_ty.validateExtern(.other, zcu); + return ty.isConstPtr(zcu) and validateExternCallconv(child_ty.fnCallingConvention(zcu)); } return true; }, @@ -3104,12 +3104,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool }, .@"fn" => { if (position != .other) return false; - // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI. - // The goal is to experiment with more integrated CPU/GPU code. - if (ty.fnCallingConvention(zcu) == .nvptx_kernel) { - return true; - } - return !target_util.fnCallConvAllowsZigTypes(ty.fnCallingConvention(zcu)); + return validateExternCallconv(ty.fnCallingConvention(zcu)); }, .@"enum" => { const enum_obj = zcu.intern_pool.loadEnumType(ty.toIntern()); @@ -3155,6 +3150,14 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool .optional => ty.isPtrLikeOptional(zcu), }; } +fn validateExternCallconv(cc: std.builtin.CallingConvention) bool { + return switch (cc) { + // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI. + // The goal is to experiment with more integrated CPU/GPU code. + .nvptx_kernel => true, + else => !target_util.fnCallConvAllowsZigTypes(cc), + }; +} /// Asserts that `ty` has resolved layout. pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {