authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-01 06:35:13+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-03 20:21:52+01:00
loge9b442db5a2b03c09f8286cab94d9ce4976bc077
tree91e2ae20683afcaa850186217ad64d45071949a2
parent2fce12b42a3662e018ad30ca874f4e7cfcdf33d2

llvm: fix C ABI integer promotion for more targets

Also stop pretending that this function handles _BitInt types correctly. Handling 32-bit integers on MIPS properly is blocked on: https://github.com/llvm/llvm-project/issues/179088

1 files changed, 56 insertions(+), 26 deletions(-)

src/codegen/llvm.zig+56-26
......@@ -12600,46 +12600,76 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key
1260012600 };
1260112601}
1260212602
12603/// This function deliberately does not handle `_BitInt` because it typically
12604/// has different ABI than regular integer types, and there is no currently no
12605/// way to determine whether a Zig integer type is meant to represent e.g. `int`
12606/// or `_BitInt(32)`.
1260312607fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness {
12604 const target = zcu.getTarget();
1260512608 switch (cc) {
1260612609 .auto, .@"inline", .async => return null,
1260712610 else => {},
1260812611 }
12612
1260912613 const int_info = switch (ty.zigTypeTag(zcu)) {
1261012614 .bool => Type.u1.intInfo(zcu),
1261112615 else => if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else return null,
1261212616 };
12613 return switch (target.os.tag) {
12614 .driverkit, .ios, .maccatalyst, .macos, .watchos, .tvos, .visionos => switch (int_info.bits) {
12615 0...16 => int_info.signedness,
12616 else => null,
12617 },
12618 else => switch (target.cpu.arch) {
12619 .loongarch64, .riscv64, .riscv64be => switch (int_info.bits) {
12620 0...16 => int_info.signedness,
12621 32 => .signed, // LLVM always signextends 32 bit ints, unsure if bug.
12622 17...31, 33...63 => int_info.signedness,
12623 else => null,
12624 },
12617 assert(int_info.bits >= 0);
1262512618
12626 .sparc64,
12627 .powerpc64,
12628 .powerpc64le,
12629 .s390x,
12630 => switch (int_info.bits) {
12631 0...63 => int_info.signedness,
12619 const target = zcu.getTarget();
12620 return switch (target.cpu.arch) {
12621 .aarch64,
12622 .aarch64_be,
12623 => switch (target.os.tag) {
12624 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (int_info.bits) {
12625 8, 16 => int_info.signedness,
1263212626 else => null,
1263312627 },
12628 else => null,
12629 },
12630
12631 .avr,
12632 => switch (int_info.bits) {
12633 8 => int_info.signedness,
12634 else => null,
12635 },
1263412636
12635 .aarch64,
12636 .aarch64_be,
12637 => null,
12637 .lanai,
12638 => null,
1263812639
12639 else => switch (int_info.bits) {
12640 0...16 => int_info.signedness,
12641 else => null,
12642 },
12640 .loongarch64,
12641 .riscv64,
12642 .riscv64be,
12643 => switch (int_info.bits) {
12644 8, 16 => int_info.signedness,
12645 32 => .signed,
12646 else => null,
12647 },
12648
12649 .mips,
12650 .mipsel,
12651 .mips64,
12652 .mips64el,
12653 => switch (int_info.bits) {
12654 8, 16, 64 => int_info.signedness,
12655 // https://github.com/llvm/llvm-project/issues/179088
12656 // 32 => .signed,
12657 else => null,
12658 },
12659
12660 .powerpc64,
12661 .powerpc64le,
12662 .s390x,
12663 .sparc64,
12664 .ve,
12665 => switch (int_info.bits) {
12666 8, 16, 32 => int_info.signedness,
12667 else => null,
12668 },
12669
12670 else => switch (int_info.bits) {
12671 8, 16 => int_info.signedness,
12672 else => null,
1264312673 },
1264412674 };
1264512675}