authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-21 18:25:33+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-21 23:03:14+02:00
logc00966d11d8eabcb9bc4724bb98eb6bd588fe3f3
tree52fa4b7b7d10aafc870f860768cb1d7c5bbd7735
parent0d4f3cc675b71dd3729c7aebab5c47b405922cee

llvm.FuncGen: fix C ABI zero extension of bool

closes https://codeberg.org/ziglang/zig/issues/35373

1 files changed, 12 insertions(+), 10 deletions(-)

src/codegen/llvm/FuncGen.zig+12-10
......@@ -7122,8 +7122,8 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
71227122}
71237123
71247124/// This function deliberately does not handle `_BitInt` because it typically
7125/// has different ABI than regular integer types, and there is no currently no
7126/// way to determine whether a Zig integer type is meant to represent e.g. `int`
7125/// has different ABI than regular integer types, and there is currently no way
7126/// to determine whether a Zig integer type is meant to represent e.g. `int`
71277127/// or `_BitInt(32)`.
71287128pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std.lang.Signedness {
71297129 switch (cc) {
......@@ -7131,11 +7131,13 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71317131 else => {},
71327132 }
71337133
7134 const int_info = switch (ty.zigTypeTag(zcu)) {
7134 const ty_tag = ty.zigTypeTag(zcu);
7135 const int_info = switch (ty_tag) {
71357136 .bool => Type.u1.intInfo(zcu),
71367137 else => if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else return null,
71377138 };
7138 assert(int_info.bits >= 0);
7139
7140 assert(int_info.bits == 0 or (int_info.bits == 1 and ty_tag == .bool) or std.math.isPowerOfTwo(int_info.bits));
71397141
71407142 const target = zcu.getTarget();
71417143 return switch (target.cpu.arch) {
......@@ -7143,7 +7145,7 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71437145 .aarch64_be,
71447146 => switch (target.os.tag) {
71457147 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (int_info.bits) {
7146 8, 16 => int_info.signedness,
7148 1, 8, 16 => int_info.signedness,
71477149 else => null,
71487150 },
71497151 else => null,
......@@ -7151,7 +7153,7 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71517153
71527154 .avr,
71537155 => switch (int_info.bits) {
7154 8 => int_info.signedness,
7156 1, 8 => int_info.signedness,
71557157 else => null,
71567158 },
71577159
......@@ -7162,7 +7164,7 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71627164 .riscv64,
71637165 .riscv64be,
71647166 => switch (int_info.bits) {
7165 8, 16 => int_info.signedness,
7167 1, 8, 16 => int_info.signedness,
71667168 32 => .signed,
71677169 else => null,
71687170 },
......@@ -7172,7 +7174,7 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71727174 .mips64,
71737175 .mips64el,
71747176 => switch (int_info.bits) {
7175 8, 16, 64 => int_info.signedness,
7177 1, 8, 16, 64 => int_info.signedness,
71767178 32 => .signed,
71777179 else => null,
71787180 },
......@@ -7183,12 +7185,12 @@ pub fn ccAbiPromoteInt(cc: std.lang.CallingConvention, zcu: *Zcu, ty: Type) ?std
71837185 .sparc64,
71847186 .ve,
71857187 => switch (int_info.bits) {
7186 8, 16, 32 => int_info.signedness,
7188 1, 8, 16, 32 => int_info.signedness,
71877189 else => null,
71887190 },
71897191
71907192 else => switch (int_info.bits) {
7191 8, 16 => int_info.signedness,
7193 1, 8, 16 => int_info.signedness,
71927194 else => null,
71937195 },
71947196 };