rust/tests/ui/abi
Guillaume Gomez ae0e7b97e0
Rollup merge of #144066 - RalfJung:extern-c-variadics, r=workingjubilee
stabilize c-style varargs for sysv64, win64, efiapi, aapcs

This has been split up so the PR now only contains the extended_varargs_abi_support stabilization; "system" has been moved to https://github.com/rust-lang/rust/pull/145954.

**Previous (combined) PR description:**

This stabilizes extern block declarations of variadic functions with the system, sysv64, win64, efiapi, aapcs ABIs. This corresponds to the extended_varargs_abi_support and extern_system_varargs feature gates.

The feature gates were split up since it seemed like there might be further discussion needed for what exactly "system" ABI variadic functions should do, but a [consensus](https://github.com/rust-lang/rust/issues/136946#issuecomment-2967847553) has meanwhile been reached: they shall behave like "C" functions. IOW, the ABI of a "system" function is (bold part is new in this PR):
- "stdcall" for win32 targets **for non-variadic functions**
- "C" for everything else

This had been previously stabilized *without FCP* in https://github.com/rust-lang/rust/pull/116161, which got reverted in https://github.com/rust-lang/rust/pull/136897. There was also a "fun" race condition involved with the system ABI being [added](https://github.com/rust-lang/rust/pull/119587) to the list of variadic-supporting ABIs between the creation and merge of rust-lang/rust#116161.

There was a question raised [here](https://github.com/rust-lang/rust/pull/116161#issuecomment-1983829513) whether t-lang even needs to be involved for a change like this. Not sure if that has meanwhile been clarified? The behavior of the "system" ABI (a Rust-specific ABI) definitely feels like t-lang territory to me.

Fixes rust-lang/rust#100189
Cc `@rust-lang/lang`

# Stabilization report

> ## General design

>  ### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

AFAIK there is no RFC. The tracking issues are
- https://github.com/rust-lang/rust/issues/100189
- https://github.com/rust-lang/rust/issues/136946

>  ### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

The only controversial point is whether "system" ABI functions should support variadics.
- Pro: This allows crates like windows-rs to consistently use "system", see e.g. https://github.com/microsoft/windows-rs/issues/3626.
- Cons: `@workingjubilee` had some implementation concerns, but I think those have been [resolved](https://github.com/rust-lang/rust/issues/136946#issuecomment-2967847553). EDIT: turns out Jubilee still has concerns (she mentioned that in a DM); I'll let her express those.

Note that "system" is already a magic ABI we introduced to "do the right thing". This just makes it do the right thing in more cases. In particular, it means that on Windows one can almost always just do
```rust
extern "system" {
  // put all the things here
}
```
and it'll do the right thing, rather than having to split imports into non-varargs and varargs, with the varargs in a separate `extern "C"` block (and risking accidentally putting a non-vararg there).

(I am saying "almost" always because some Windows API functions actually use cdecl, not stdcall, on x86. Those of course need to go in `extern "C"` blocks.)

> ### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

Actually defining variadic functions in Rust remains unstable, under the [c_variadic feature gate](https://github.com/rust-lang/rust/issues/44930).

> ## Has a Call for Testing period been conducted? If so, what feedback was received?
>
> Does any OSS nightly users use this feature? For instance, a useful indication might be "search <grep.app> for `#![feature(FEATURE_NAME)]` and had `N` results".

There was no call for testing.

A search brings up https://github.com/rust-osdev/uefi-rs/blob/main/uefi-raw/src/table/boot.rs using this for "efiapi". This doesn't seem widely used, but it is an "obvious" gap in our support for c-variadics.

> ## Implementation quality

All rustc does here is forward the ABI to LLVM so there's lot a lot to say here...

> ### Summarize the major parts of the implementation and provide links into the code (or to PRs)
>
> An example for async closures: <https://rustc-dev-guide.rust-lang.org/coroutine-closures.html>.

The check for allowed variadic ABIs is [here](9c870d30e2/compiler/rustc_hir_analysis/src/lib.rs (L109-L126)).

The special handling of "system" is [here](c24914ec83/compiler/rustc_target/src/spec/abi_map.rs (L82-L85)).

> ### Summarize existing test coverage of this feature
>
> Consider what the "edges" of this feature are.  We're particularly interested in seeing tests that assure us about exactly what nearby things we're not stabilizing.
>
> Within each test, include a comment at the top describing the purpose of the test and what set of invariants it intends to demonstrate. This is a great help to those reviewing the tests at stabilization time.
>
> - What does the test coverage landscape for this feature look like?
>   - Tests for compiler errors when you use the feature wrongly or make mistakes?
>   - Tests for the feature itself:
>       - Limits of the feature (so failing compilation)
>       - Exercises of edge cases of the feature
>       - Tests that checks the feature works as expected (where applicable, `//@ run-pass`).
>   - Are there any intentional gaps in test coverage?
>
> Link to test folders or individual tests (ui/codegen/assembly/run-make tests, etc.).

Prior PRs add a codegen test for all ABIs and tests actually calling extern variadic functions for sysv64 and win64:
- https://github.com/rust-lang/rust/pull/144359
- https://github.com/rust-lang/rust/pull/144379

We don't have a way of executing uefi target code in the test suite, so it's unclear how to fully test efiapi. aapcs could probably be done? (But note that we have hardly an such actually-calling-functions tests for ABI things, we almost entirely rely on codegen tests.)

The test ensuring that we do *not* stabilize *defining* c-variadic functions is `tests/ui/feature-gates/feature-gate-c_variadic.rs`.

> ### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

None that I am aware of.

> ### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None that I am aware of.

> ### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization

`@Soveu` added sysv64, win64, efiapi, aapcs to the list of ABIs that allow variadics, `@beepster4096` added system.  `@workingjubilee` recently refactored the ABI handling in the compiler, also affecting this feature.

> ### Which tools need to be adjusted to support this feature. Has this work been done?
>
> Consider rustdoc, clippy, rust-analyzer, rustfmt, rustup, docs.rs.

Maybe RA needs to be taught about the new allowed ABIs? No idea how precisely they mirror what exactly rustc accepts and rejects here.

> ## Type system and execution rules

> ### What compilation-time checks are done that are needed to prevent undefined behavior?
>
>  (Be sure to link to tests demonstrating that these tests are being done.)

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

> ### Does the feature's implementation need checks to prevent UB or is it sound by default and needs opt in in places to perform the dangerous/unsafe operations? If it is not sound by default, what is the rationale?

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

> ### Can users use this feature to introduce undefined behavior, or use this feature to break the abstraction of Rust and expose the underlying assembly-level implementation? (Describe.)

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

> ### What updates are needed to the reference/specification? (link to PRs when they exist)

- https://github.com/rust-lang/reference/pull/1936

> ## Common interactions

> ### Does this feature introduce new expressions and can they produce temporaries? What are the lifetimes of those temporaries?

No.

> ### What other unstable features may be exposed by this feature?

None.
2025-09-02 17:08:52 +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 Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +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 Error on invalid signatures for interrupt ABIs 2025-06-24 14:40:11 +02:00
bad-custom.stderr setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03: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 Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02: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 Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02:00
c-zst.sparc64-linux.stderr Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02: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 Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02:00
cabi-int-widening.rs Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
cannot-be-called.avr.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.i686.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.msp430.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.riscv32.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.riscv64.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.rs Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.x64.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-called.x64_win.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-coroutine.avr.stderr setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
cannot-be-coroutine.i686.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-coroutine.msp430.stderr setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
cannot-be-coroutine.riscv32.stderr setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
cannot-be-coroutine.riscv64.stderr setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
cannot-be-coroutine.rs Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-coroutine.x64.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
cannot-be-coroutine.x64_win.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03: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.generic.stderr Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02:00
debug.loongarch64.stderr Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02:00
debug.riscv64.stderr Use captures(address) instead of captures(none) for indirect args 2025-08-26 16:16:23 +02:00
debug.rs Fix the ABI parameter inconsistency issue in debug.rs for LoongArch64 2025-08-21 20:04:02 +08:00
explicit_repr_rust.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
extern-c-two-doubles-x86_64-5754.rs Rehome tests/ui/issues/ tests [3/?] 2025-08-04 16:43:53 -04:00
fixed_x18.rs Rename tests/codegen into tests/codegen-llvm 2025-07-22 14:28:48 +02:00
homogenous-floats-target-feature-mixup.rs Remove uses of #[feature(avx512_target_feature)] 2025-05-18 11:12:25 +05:30
interrupt-invalid-signature.avr.stderr tests: add test for invalid interrupt signatures 2025-06-27 11:04:04 -07:00
interrupt-invalid-signature.i686.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
interrupt-invalid-signature.msp430.stderr tests: add test for invalid interrupt signatures 2025-06-27 11:04:04 -07:00
interrupt-invalid-signature.riscv32.stderr tests: add test for invalid interrupt signatures 2025-06-27 11:04:04 -07:00
interrupt-invalid-signature.riscv64.stderr tests: add test for invalid interrupt signatures 2025-06-27 11:04:04 -07:00
interrupt-invalid-signature.rs Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
interrupt-invalid-signature.x64.stderr Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
interrupt-returns-never-or-unit.rs Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
invalid-call-abi-ctfe.rs Taint body on invalid call ABI 2025-06-24 22:43:00 +00:00
invalid-call-abi-ctfe.stderr Taint body on invalid call ABI 2025-06-24 22:43:00 +00:00
invalid-call-abi.rs Add rust-invalid ABI 2025-06-24 22:34:30 +00:00
invalid-call-abi.stderr Add rust-invalid ABI 2025-06-24 22:34:30 +00:00
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 minicore: use core's diagnostic::on_unimplemented messages 2025-07-03 10:22:40 +02: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 tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00: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 update some s390x codegen tests 2025-08-20 16:35:33 +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-abi-transmute.rs tests: migrate unsupported-abi-transmute.rs to extern "rust-invalid" 2025-06-25 00:54:02 -07:00
unsupported-abi-transmute.stderr tests: migrate unsupported-abi-transmute.rs to extern "rust-invalid" 2025-06-25 00:54:02 -07:00
unsupported-in-impls.rs tests: migrate unsupported-abi-transmute.rs to extern "rust-invalid" 2025-06-25 00:54:02 -07:00
unsupported-in-impls.stderr tests: split out unsupported-in-impls.rs 2025-06-25 00:54:02 -07:00
unsupported-varargs-fnptr.rs stabilize extended_varargs_abi_support 2025-09-02 08:48:12 +02:00
unsupported-varargs-fnptr.stderr stabilize extended_varargs_abi_support 2025-09-02 08:48:12 +02:00
unsupported.aarch64.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
unsupported.arm.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
unsupported.i686.stderr tests: bless s/C-cmse/cmse/ 2025-06-25 00:52:11 -07:00
unsupported.riscv32.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
unsupported.riscv64.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
unsupported.rs Rollup merge of #142992 - workingjubilee:dont-validate-naughty-abis, r=jieyouxu 2025-06-25 22:14:56 +02:00
unsupported.x64.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
unsupported.x64_win.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02: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