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...@@ -12600,46 +12600,76 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key
12600 };12600 };
12601}12601}
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)`.
12603fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness {12607fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness {
12604 const target = zcu.getTarget();
12605 switch (cc) {12608 switch (cc) {
12606 .auto, .@"inline", .async => return null,12609 .auto, .@"inline", .async => return null,
12607 else => {},12610 else => {},
12608 }12611 }
12612
12609 const int_info = switch (ty.zigTypeTag(zcu)) {12613 const int_info = switch (ty.zigTypeTag(zcu)) {
12610 .bool => Type.u1.intInfo(zcu),12614 .bool => Type.u1.intInfo(zcu),
12611 else => if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else return null,12615 else => if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else return null,
12612 };12616 };
12613 return switch (target.os.tag) {12617 assert(int_info.bits >= 0);
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 },
1262512618
12626 .sparc64,12619 const target = zcu.getTarget();
12627 .powerpc64,12620 return switch (target.cpu.arch) {
12628 .powerpc64le,12621 .aarch64,
12629 .s390x,12622 .aarch64_be,
12630 => switch (int_info.bits) {12623 => switch (target.os.tag) {
12631 0...63 => int_info.signedness,12624 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (int_info.bits) {
12625 8, 16 => int_info.signedness,
12632 else => null,12626 else => null,
12633 },12627 },
12628 else => null,
12629 },
12630
12631 .avr,
12632 => switch (int_info.bits) {
12633 8 => int_info.signedness,
12634 else => null,
12635 },
1263412636
12635 .aarch64,12637 .lanai,
12636 .aarch64_be,12638 => null,
12637 => null,
1263812639
12639 else => switch (int_info.bits) {12640 .loongarch64,
12640 0...16 => int_info.signedness,12641 .riscv64,
12641 else => null,12642 .riscv64be,
12642 },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,
12643 },12673 },
12644 };12674 };
12645}12675}