rust/tests/ui/abi
León Orell Valerian Liehr 16152661ff
Rollup merge of #142389 - beetrees:cranelift-arg-ext, r=bjorn3
Apply ABI attributes on return types in `rustc_codegen_cranelift`

- The [x86-64 System V ABI standard](https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build) doesn't sign/zero-extend integer arguments or return types.
- But the de-facto standard as implemented by Clang and GCC is to sign/zero-extend arguments to 32 bits (but not return types).
- Additionally, Apple targets [sign/zero-extend both arguments and return values to 32 bits](https://developer.apple.com/documentation/xcode/writing-64-bit-intel-code-for-apple-platforms#Pass-arguments-to-functions-correctly).
- However, the `rustc_target` ABI adjustment code currently [unconditionally extends both arguments and return values to 32 bits](https://github.com/rust-lang/rust/blame/e703dff8fe220b78195c53478e83fb2f68d8499c/compiler/rustc_target/src/callconv/x86_64.rs#L240) on all targets.
- This doesn't cause a miscompilation when compiling with LLVM as LLVM will ignore the `signext`/`zeroext` attribute when applied to return types on non-Apple x86-64 targets.
- Cranelift, however, does not have a similar special case, requiring `rustc` to set the argument extension attribute correctly.
- However, `rustc_codegen_cranelift` doesn't currently apply ABI attributes to return types at all, meaning `rustc_codegen_cranelift` will currently miscompile `i8`/`u8`/`i16`/`u16` returns on x86-64 Apple targets as those targets require sign/zero-extension of return types.

This PR fixes the bug(s) by making the `rustc_target` x86-64 System V ABI only mark return types as sign/zero-extended on Apple platforms, while also making `rustc_codegen_cranelift` apply ABI attributes to return types. The RISC-V and s390x C ABIs also require sign/zero extension of return types, so this will fix those targets when building with `rustc_codegen_cranelift` too.

r? `````@bjorn3`````
2025-06-15 23:51:56 +02:00
..
cross-crate tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
extern tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
foreign tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issues Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
mir Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
numbers-arithmetic Apply ABI attributes on return types in rustc_codegen_cranelift 2025-06-12 00:47:01 +01:00
statics Update tests for hidden references to mutable static 2024-09-13 14:10:56 +03:00
struct-enums Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
union Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
abi-sysv64-arg-passing.rs Enable more tests on Windows 2025-02-03 10:39:32 -05:00
abi-sysv64-register-usage.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
abi-typo-unstable.feature_disabled.stderr update/bless tests 2025-04-06 21:41:47 +02:00
abi-typo-unstable.feature_enabled.stderr update/bless tests 2025-04-06 21:41:47 +02:00
abi-typo-unstable.rs update/bless tests 2025-04-06 21:41:47 +02:00
anon-extern-mod.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
arm-unadjusted-intrinsic.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
bad-custom.rs add extern "custom" functions 2025-06-12 20:27:10 +02:00
bad-custom.stderr add extern "custom" functions 2025-06-12 20:27:10 +02:00
c-stack-as-value.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
c-stack-returning-int64.rs Use the rustc_private libc less in tests 2024-04-15 08:54:11 -04:00
c-zst.aarch64-darwin.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
c-zst.powerpc-linux.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
c-zst.rs use add-core-stubs / minicore for a few more tests 2025-02-16 18:37:50 +01:00
c-zst.s390x-linux.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
c-zst.sparc64-linux.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
c-zst.x86_64-linux.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
c-zst.x86_64-pc-windows-gnu.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
cabi-int-widening.rs Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
compatibility.rs Remove redundant min-llvm-version annotations for LoongArch tests 2025-05-01 08:50:14 +08:00
custom.rs add extern "custom" functions 2025-06-12 20:27:10 +02:00
debug.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
debug.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
explicit_repr_rust.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fixed_x18.rs UI tests: migrate remaining compile time error-patterns to line annotations 2025-04-13 21:48:53 +03:00
homogenous-floats-target-feature-mixup.rs Remove uses of #[feature(avx512_target_feature)] 2025-05-18 11:12:25 +05:30
issue-28676.rs Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
large-byval-align.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
nullable-pointer-ffi-compat.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
relocation_model_pic.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
riscv-discoverability-guidance.riscv32.stderr Rollup merge of #137771 - estebank:abi-sugg, r=compiler-errors 2025-03-01 05:49:56 +01:00
riscv-discoverability-guidance.riscv64.stderr Rollup merge of #137771 - estebank:abi-sugg, r=compiler-errors 2025-03-01 05:49:56 +01:00
riscv-discoverability-guidance.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
rust-cold-works-with-rustic-args.rs compiler: use is_rustic_abi in ty_utils 2025-03-04 19:57:51 -08:00
rustcall-generic.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
segfault-no-out-of-stack.rs Insert null checks for pointer dereferences when debug assertions are enabled 2025-01-31 11:13:34 +00:00
shadow-call-stack-without-fixed-x18.rs compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
simd-abi-checks-avx.rs Remove uses of #[feature(avx512_target_feature)] 2025-05-18 11:12:25 +05:30
simd-abi-checks-avx.stderr Remove uses of #[feature(avx512_target_feature)] 2025-05-18 11:12:25 +05:30
simd-abi-checks-empty-list.rs make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-empty-list.stderr make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-s390x.rs make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-s390x.z10.stderr make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-s390x.z13_no_vector.stderr make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-s390x.z13_soft_float.stderr make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-sse.rs make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-abi-checks-sse.stderr make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
sparcv8plus-llvm19.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus-llvm19.sparc.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus-llvm19.sparc_cpu_v9.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus-llvm19.sparc_cpu_v9_feature_v8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus-llvm19.sparc_feature_v8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus-llvm19.sparcv8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.sparc.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.sparc_cpu_v9.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.sparc_feature_v8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
sparcv8plus.sparcv8plus.stderr tests: use minicore more 2025-02-24 09:26:54 +00:00
stack-probes-lto.rs tests: use needs-subprocess instead of ignore-{wasm32,emscripten,sgx} 2025-01-23 20:51:29 +08:00
stack-probes.rs tests: use needs-subprocess instead of ignore-{wasm32,emscripten,sgx} 2025-01-23 20:51:29 +08:00
stack-protector.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
sysv64-zst.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
sysv64-zst.stderr Remove rustc's notion of "preferred" alignment AKA __alignof 2025-06-08 16:41:46 -07:00
unsized-args-in-c-abi-issues-94223-115845.rs Delete tuple unsizing 2025-02-27 10:26:33 +00:00
unsupported.aarch64.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
unsupported.arm.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
unsupported.i686.stderr tests: bless unsupported_calling_conventions linting on some fn_ptrs 2025-06-09 15:50:01 -07:00
unsupported.riscv32.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
unsupported.riscv64.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
unsupported.rs tests: bless unsupported_calling_conventions linting on some fn_ptrs 2025-06-09 15:50:01 -07:00
unsupported.x64.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
unsupported.x64_win.stderr tests: Bless for weaker unsupported_calling_conventions 2025-06-11 09:58:52 -07:00
variadic-ffi.rs Allow "C-unwind" fn to have C variadics 2024-06-22 15:14:14 -07:00
vectorcall-abi-checks.rs UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
vectorcall-abi-checks.stderr vectorcall ABI: error if sse2 is not available 2025-02-20 12:40:58 +01:00
x86stdcall.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
x86stdcall2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00