rust/tests/codegen
Chris Denton 1ca5e4f1c1
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgross35,Amanieu,traviscross
Stabilize `naked_functions`

tracking issue: https://github.com/rust-lang/rust/issues/90957
request for stabilization on tracking issue: https://github.com/rust-lang/rust/issues/90957#issuecomment-2539270352
reference PR: https://github.com/rust-lang/reference/pull/1689

# Request for Stabilization

Two years later, we're ready to try this again. Even though this issue is already marked as having passed FCP, given the amount of time that has passed and the changes in implementation strategy, we should follow the process again.

## Summary

The `naked_functions` feature has two main parts: the `#[naked]` function attribute, and the `naked_asm!` macro.

An example of a naked function:

```rust
const THREE: usize = 3;

#[naked]
pub extern "sysv64" fn add_n(number: usize) -> usize {
    // SAFETY: the validity of the used registers
    // is guaranteed according to the "sysv64" ABI
    unsafe {
        core::arch::naked_asm!(
            "add rdi, {}",
            "mov rax, rdi",
            "ret",
            const THREE,
        )
    }
}
```

When the `#[naked]` attribute is applied to a function, the compiler won't emit a [function prologue](https://en.wikipedia.org/wiki/Function_prologue_and_epilogue) or epilogue when generating code for this function. This attribute is analogous to [`__attribute__((naked))`](https://developer.arm.com/documentation/100067/0608/Compiler-specific-Function--Variable--and-Type-Attributes/--attribute----naked---function-attribute) in C. The use of this feature allows the programmer to have precise control over the assembly that is generated for a given function.

The body of a naked function must consist of a single `naked_asm!` invocation, a heavily restricted variant of the `asm!` macro: the only legal operands are `const` and `sym`, and the only legal options are `raw` and `att_syntax`. In lieu of specifying operands, the `naked_asm!` within a naked function relies on the function's calling convention to determine the validity of registers.

## Documentation

The Rust Reference: https://github.com/rust-lang/reference/pull/1689
(Previous PR: https://github.com/rust-lang/reference/pull/1153)

## Tests

* [tests/run-make/naked-symbol-visiblity](https://github.com/rust-lang/rust/tree/master/tests/codegen/naked-fn) verifies that `pub`, `#[no_mangle]` and `#[linkage = "..."]` work correctly for naked functions
* [tests/codegen/naked-fn](https://github.com/rust-lang/rust/tree/master/tests/codegen/naked-fn) has tests for function alignment, use of generics, and validates the exact assembly output on linux, macos, windows and thumb
* [tests/ui/asm/naked-*](https://github.com/rust-lang/rust/tree/master/tests/ui/asm) tests for incompatible attributes, generating errors around incorrect use of `naked_asm!`, etc

## Interaction with other (unstable) features

### [fn_align](https://github.com/rust-lang/rust/issues/82232)

Combining `#[naked]` with `#[repr(align(N))]` works well, and is tested e.g. here

- https://github.com/rust-lang/rust/blob/master/tests/codegen/naked-fn/aligned.rs
- https://github.com/rust-lang/rust/blob/master/tests/codegen/naked-fn/min-function-alignment.rs

It's tested extensively because we do need to explicitly support the `repr(align)` attribute (and make sure we e.g. don't mistake powers of two for number of bytes).

## History

This feature was originally proposed in [RFC 1201](https://github.com/rust-lang/rfcs/pull/1201), filed on 2015-07-10 and accepted on 2016-03-21. Support for this feature was added in [#32410](https://github.com/rust-lang/rust/pull/32410), landing on 2016-03-23. Development languished for several years as it was realized that the semantics given in RFC 1201 were insufficiently specific. To address this, a minimal subset of naked functions was specified by [RFC 2972](https://github.com/rust-lang/rfcs/pull/2972), filed on 2020-08-07 and accepted on 2021-11-16. Prior to the acceptance of RFC 2972, all of the stricter behavior specified by RFC 2972 was implemented as a series of warn-by-default lints that would trigger on existing uses of the `naked` attribute; these lints became hard errors in [#93153](https://github.com/rust-lang/rust/pull/93153) on 2022-01-22. As a result, today RFC 2972 has completely superseded RFC 1201 in describing the semantics of the `naked` attribute.

More recently, the `naked_asm!` macro was added to replace the earlier use of a heavily restricted `asm!` invocation. The `naked_asm!` name is clearer in error messages, and provides a place for documenting the specific requirements of inline assembly in naked functions.

The implementation strategy was changed to emitting a global assembly block. In effect, an extern function

```rust
extern "C" fn foo() {
    core::arch::naked_asm!("ret")
}
```

is emitted as something similar to

```rust
core::arch::global_asm!(
    "foo:",
    "ret"
);

extern "C" {
    fn foo();
}
```

The codegen approach was chosen over the llvm naked function attribute because:

- the rust compiler can guarantee the behavior (no sneaky additional instructions, no inlining, etc.)
- behavior is the same on all backends (llvm, cranelift, gcc, etc)

Finally, there is now an allow list of compatible attributes on naked functions, so that e.g. `#[inline]` is rejected with an error. The `#[target_feature]` attribute on naked functions was later made separately unstable, because implementing it is complex and we did not want to block naked functions themselves on how target features work on them. See also https://github.com/rust-lang/rust/issues/138568.

relevant PRs for these recent changes

- https://github.com/rust-lang/rust/pull/127853
- https://github.com/rust-lang/rust/pull/128651
- https://github.com/rust-lang/rust/pull/128004
- https://github.com/rust-lang/rust/pull/138570
-
### Various historical notes

#### `noreturn`
[RFC 2972](https://github.com/rust-lang/rfcs/blob/master/text/2972-constrained-naked.md) mentions that naked functions

> must have a body which contains only a single asm!() statement which:
> iii. must contain the noreturn option.

Instead of `asm!`, the current implementation mandates that the body contain a single `naked_asm!` statement. The `naked_asm!` macro is a heavily restricted version of the `asm!` macro, making it easier to talk about and document the rules of assembly in naked functions and give dedicated error messages.

For `naked_asm!`, the behavior of the `asm!`'s `noreturn` option is implicit. The `noreturn` option means that it is UB for control flow to fall through the end of the assembly block. With `asm!`, this option is usually used for blocks that diverge (and thus have no return and can be typed as `!`). With `naked_asm!`, the intent is different: usually naked funtions do return, but they must do so from within the assembly block. The `noreturn` option was used so that the compiler would not itself also insert a `ret` instruction at the very end.

#### padding / `ud2`

A `naked_asm!` block that violates the safety assumption that control flow must not fall through the end of the assembly block is UB. Because no return instruction is emitted, whatever bytes follow the naked function will be executed, resulting in truly undefined behavior. There has been discussion whether rustc should emit an invalid instruction (e.g. `ud2`  on x86) after the `naked_asm!` block to at least fail early in the case of an invalid `naked_asm!`. It was however decided that it is more useful to guarantee that `#[naked]` functions NEVER contain any instructions besides those in the `naked_asm!` block.

# unresolved questions

None

r? ``@Amanieu``

I've validated the tests on x86_64 and aarch64
2025-04-21 18:53:15 +00:00
..
asm Use explicit cpu in some asm and codegen tests. 2025-03-19 19:45:46 +01:00
autodiff move old tests, add sret test 2025-04-07 07:11:52 -04:00
auxiliary Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
avr update/bless tests 2025-04-06 21:41:47 +02:00
bounds-checking Simplify the GEP instruction for index 2024-12-15 19:01:45 +08:00
cffi stabilize naked_functions 2025-04-20 11:18:38 +02:00
compiletest-self-test tests/codegen: add minicore compiletest self-test 2024-10-31 18:20:11 +08:00
cross-crate-inlining tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
debug-accessibility Explicitly register MSVC/NONMSVC revisions for some codegen tests 2024-12-19 20:36:51 +08:00
debuginfo-proc-macro Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
dllimports Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
enum Include optional dso_local marker for functions in enum-match.rs 2025-04-15 22:18:10 -05:00
ergonomic-clones Add codegen test to be sure we get rid of uneeded clones after monomorphization 2025-04-07 16:53:11 -03:00
float Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
hint tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
instrument-coverage coverage: Adjust a codegen test to ignore the order of covmap/covfun globals 2024-12-11 21:34:48 +11:00
instrument-xray [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
intrinsics Move select_unpredictable to the hint module 2025-04-13 01:34:25 +01:00
issues tests: adjust 101082 test for LLVM 21 fix 2025-04-17 15:11:21 -04:00
lib-optimizations tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
loongarch-abi tests: use minicore more 2025-02-24 09:26:54 +00:00
macos tests: use minicore more 2025-02-24 09:26:54 +00:00
meta-filecheck compiletest: don't register MSVC/NONMSVC FileCheck prefixes 2024-12-19 20:36:51 +08:00
naked-fn stabilize naked_functions 2025-04-20 11:18:38 +02:00
non-terminate Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
patchable-function-entry Updated code for changes to RFC, added additional error handling, added 2024-06-25 19:00:02 +02:00
remap_path_prefix tests: use //@ ignore-auxiliary with backlinked primary test file 2025-04-17 19:45:28 +08:00
repr tests: use minicore more 2025-02-24 09:26:54 +00:00
riscv-abi tests: use minicore more 2025-02-24 09:26:54 +00:00
sanitizer KCFI: Add KCFI arity indicator support 2025-04-05 04:05:04 +00:00
simd Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu 2025-04-11 10:53:45 +00:00
simd-intrinsic simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
src-hash-algorithm [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
unwind-abis Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
aarch64-softfloat.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
aarch64-struct-align-128.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-efiapi.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-main-signature-16bit-c-int.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
abi-main-signature-32bit-c-int.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
abi-repr-ext.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-sysv64.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-win64-zst.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-x86-interrupt.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
abi-x86-sse.rs x86-sse2 ABI: use SSE registers for floats and SIMD 2025-02-18 16:11:41 +01:00
abi-x86_64_sysv.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
addr-of-mutate.rs LLVM changed the nocapture attribute to captures(none) 2025-01-30 11:22:46 +01:00
adjustments.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
align-byval-alignment-mismatch.rs use add-core-stubs / minicore for a few more tests 2025-02-16 18:37:50 +01:00
align-byval-vector.rs use add-core-stubs / minicore for a few more tests 2025-02-16 18:37:50 +01:00
align-byval.rs use add-core-stubs / minicore for a few more tests 2025-02-16 18:37:50 +01:00
align-enum.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
align-fn.rs fix multiple #[repr(align(N))] on functions 2025-04-16 12:16:40 +02:00
align-offset.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
align-struct.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
alloc-optimisation.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
amdgpu-addrspacecast.rs Cast allocas to default address space 2025-02-10 21:38:44 +01:00
array-clone.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-cmp.rs Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
array-codegen.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-equality.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-from_fn.rs test(std): Add codegen test for array::from_fn optimization 2024-08-10 10:44:24 +08:00
array-map.rs use [N x i8] for alloca types 2024-04-11 21:42:35 -04:00
array-optimized.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-repeat.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
ascii-char.rs codegen tests: Tolerate nuw nsw on trunc 2024-04-11 17:20:08 +00:00
assign-desugar-debuginfo.rs Don't produce debug information for compiler-introduced-vars when desugaring assignments. 2025-03-21 17:34:45 -07:00
async-closure-debug.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
async-fn-debug-awaitee-field.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
async-fn-debug-msvc.rs didn't catch this test failure, whoops 2025-04-11 09:57:21 +02:00
async-fn-debug.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
atomic-operations.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
atomicptr.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
autodiffv2.rs passing test for dualv 2025-04-16 17:13:50 -04:00
autovectorize-f32x4.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
bigint-helpers.rs Override disjoint_or in the LLVM backend 2025-01-31 22:29:08 -08:00
binary-heap-peek-mut-pop-no-panic.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
binary-search-index-no-bound-check.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
bool-cmp.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
box-default-debug-copies.rs reduce Box::default stack copies in debug mode 2025-01-26 03:48:27 -05:00
box-uninit-bytes.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
bpf-alu32.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
branch-protection.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
call-llvm-intrinsics.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
cast-optimized.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
cast-target-abi.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
catch-unwind.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
cdylib-external-inline-fns.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
cf-protection.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
cfguard-checks.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
cfguard-disabled.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
cfguard-nochecks.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
cfguard-non-msvc.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
char-ascii-branchless.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
char-escape-debug-no-bounds-check.rs Add test for escape_debug without bounds check. 2025-03-06 21:38:39 +01:00
checked_ilog.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
checked_math.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
clone-shims.rs Let InstCombine remove Clone shims inside Clone shims 2024-07-25 15:14:42 -04:00
clone_as_copy.rs Remove unsound-mir-opts for simplify_aggregate_to_copy 2025-04-03 21:59:43 +08:00
codemodels.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
coercions.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
cold-call-declare-and-call.rs Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
common_prim_int_ptr.rs llvm: Tolerate captures in tests 2025-02-14 18:55:50 +00:00
comparison-operators-2-struct.rs Update some comparison tests now that they pass in LLVM20 2025-02-17 16:36:14 -08:00
comparison-operators-2-tuple.rs Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics 2025-03-06 22:29:05 +08:00
comparison-operators-newtype.rs Set signext or zeroext for integer arguments on RISC-V 2024-10-23 04:42:03 +02:00
const-array.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
const-vector.rs Ban non-array SIMD 2024-09-09 19:39:43 -07:00
const_scalar_pair.rs Fix tests and bless 2024-04-24 13:12:33 +01:00
constant-branch.rs Compute reachable locals as part of non_ssa_locals 2024-09-21 01:07:00 -04:00
consts.rs Use FileCheck to parameterize codegen tests over hashes 2024-06-04 01:30:51 -07:00
coroutine-debug-msvc.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
coroutine-debug.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
dealloc-no-unwind.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
debug-alignment.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-column-msvc.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-column.rs Enable more tests on Windows 2025-02-03 10:39:32 -05:00
debug-compile-unit-path.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
debug-fndef-size.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
debug-limited.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-line-directives-only.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-line-tables-only.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-linkage-name.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
debug-vtable.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
debuginfo-constant-locals.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
debuginfo-generic-closure-env-names.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
debuginfo-inline-callsite-location.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
deduced-param-attrs.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
default-requires-uwtable.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
default-visibility.rs Use Default visibility for rustc-generated C symbol declarations 2024-10-11 08:43:27 +11:00
direct-access-external-data.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
dont-shuffle-bswaps.rs Use -C target-cpu=z13 on s390x vector test 2025-04-07 09:36:56 +02:00
dont_codegen_private_const_fn_only_used_in_const_eval.rs Also support generic constants 2024-06-05 15:40:11 +00:00
drop-in-place-noalias.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
drop.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
dst-offset.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
dst-vtable-align-nonzero.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
dst-vtable-size-range.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
ehcontguard_disabled.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
ehcontguard_enabled.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
emscripten-catch-unwind-js-eh.rs update/bless tests 2025-04-06 21:41:47 +02:00
emscripten-catch-unwind-wasm-eh.rs update/bless tests 2025-04-06 21:41:47 +02:00
enable-lto-unit-splitting.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
error-provide.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
export-no-mangle.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
external-no-mangle-fns.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
external-no-mangle-statics.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
f128-wasm32-callconv.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
fastcall-inreg.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
fatptr.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
fewer-names.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
fixed-x18.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
float_math.rs Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
fn-impl-trait-self.rs Update test directives for wasm32-wasip1 2024-03-11 09:36:35 -07:00
force-frame-pointers.rs test: ignore force-frame-pointers test on some targets 2024-06-23 00:40:43 -07:00
force-no-unwind-tables.rs Enable more tests on Windows 2025-02-03 10:39:32 -05:00
force-unwind-tables.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
frame-pointer.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
function-arguments-noopt.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
function-arguments.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
function-return.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
gdb_debug_script_load.rs remove support for the #[start] attribute 2025-01-21 06:59:15 -07:00
generic-debug.rs reenable some windows tests 2024-07-14 13:48:29 +03:00
gep-index.rs Also use gep inbounds nuw for index projections 2025-02-19 15:15:29 +01:00
gpu-kernel-abi.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
i128-wasm32-callconv.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
i128-x86-align.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
i128-x86-callconv.rs x86_win64 ABI: do not use xmm0 with softfloat ABI 2025-02-19 08:41:19 +01:00
infallible-unwrap-in-opt-z.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
inherit_overflow.rs Codegen const panic messages as function calls 2024-03-22 09:55:50 -04:00
inline-always-works-always.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
inline-debuginfo.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
inline-function-args-debug-info.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
inline-hint.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
instrument-mcount.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
integer-cmp.rs Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics 2025-03-06 22:29:05 +08:00
integer-overflow.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
internalize-closures.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
intrinsic-no-unnamed-attr.rs replace some #[rustc_intrinsic] usage with use of the libcore declarations 2025-04-16 14:48:20 +02:00
is_val_statically_known.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
issue-97217.rs Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
iter-repeat-n-trivial-drop.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
layout-size-checks.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
lifetime_start_end.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
link-dead-code.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
link_section.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
llvm-ident.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
llvm_module_flags.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
loads.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
local-generics-in-exe-internalized.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
lto-removes-invokes.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
mainsubprogram.rs reenable some windows tests 2024-07-14 13:48:29 +03:00
match-optimized.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
match-optimizes-away.rs Don't alloca just to look at a discriminant 2025-03-12 00:56:43 -07:00
match-unoptimized.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
maybeuninit-rvo.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
mem-replace-big-type.rs We don't need NonNull::as_ptr debuginfo 2024-12-10 01:29:43 -08:00
mem-replace-simple-type.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
merge-functions.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
method-declaration.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
min-function-alignment.rs add -Zmin-function-alignment 2025-01-10 22:53:54 +01:00
mir-aggregate-no-alloca.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
mir-inlined-line-numbers.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
mir_zst_stores.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
move-before-nocapture-ref-arg.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
move-operands.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
naked-asan.rs stabilize naked_functions 2025-04-20 11:18:38 +02:00
no-alloca-inside-if-false.rs Compute reachable locals as part of non_ssa_locals 2024-09-21 01:07:00 -04:00
no-assumes-on-casts.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
no-dllimport-w-cross-lang-lto.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
no-jump-tables.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
no-plt.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
no-redundant-item-monomorphization.rs Port issue-7349 to a codegen test 2024-04-04 21:59:08 +01:00
no_builtins-at-crate.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
noalias-box-off.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noalias-box.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noalias-flag.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noalias-freeze.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
noalias-refcell.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noalias-rwlockreadguard.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noalias-unpin.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
noreturn-uninhabited.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
noreturnflag.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
nounwind.rs reenable some windows tests 2024-07-14 13:48:29 +03:00
nrvo.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
optimize-attr-1.rs Implement optimize(none) attribute 2025-01-23 17:19:53 +00:00
option-as-slice.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
option-niche-eq.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
overaligned-constant.rs The embedded bitcode should always be prepared for LTO/ThinLTO 2025-02-23 21:23:36 +08:00
packed.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
panic-abort-windows.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
panic-in-drop-abort.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
panic-unwind-default-uwtable.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
pattern_type_symbols.rs Hide the end of ranges in pretty printing if it's also the maximum of the type 2025-03-06 10:50:23 +00:00
personality_lifetimes.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
pgo-counter-bias.rs Use -Zno-profiler-runtime instead of //@ needs-profiler-support 2024-06-14 13:31:46 +10:00
pgo-instrumentation.rs Use -Zno-profiler-runtime instead of //@ needs-profiler-support 2024-06-14 13:31:46 +10:00
pic-relocation-model.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
pie-relocation-model.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
placement-new.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
powerpc64le-struct-align-128.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
precondition-checks.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
ptr-arithmetic.rs Emit getelementptr inbounds nuw for pointer::add() 2025-02-19 11:32:32 +01:00
ptr-read-metadata.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
range-attribute.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
range-loop.rs Allow more top-down inlining for single-BB callees 2025-03-12 22:39:43 -07:00
range_to_inclusive.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
README.md
refs.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
reg-struct-return.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
regparm-inreg.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
repeat-trusted-len.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
riscv-target-abi.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
rust-abi-arch-specific-adjustment.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
s390x-simd.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
scalar-pair-bool.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
set-discriminant-invalid.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
skip-mono-inside-if-false.rs Avoid lowering code under dead SwitchInt targets 2024-03-12 19:01:04 -04:00
slice-as_chunks.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-indexing.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-init.rs Add a test 2025-03-02 18:53:49 +00:00
slice-is-ascii.rs Use explicit cpu in some asm and codegen tests. 2025-03-19 19:45:46 +01:00
slice-iter-fold.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-iter-len-eq-zero.rs transmute should also assume non-null pointers 2025-02-12 23:01:27 -08:00
slice-iter-nonnull.rs Simplify slice::Iter::next enough that it inlines 2025-02-14 22:24:27 -08:00
slice-last-elements-optimization.rs Add tests for LLVM 20 slice bounds check optimization 2025-03-31 22:38:53 +09:00
slice-pointer-nonnull-unwrap.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-position-bounds-check.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-ref-equality.rs Set both nuw and nsw in slice size calculation 2025-02-13 21:26:48 -08:00
slice-reverse.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-split-at.rs slice: Remove some uses of unsafe in first/last chunk methods 2025-03-30 12:45:04 -04:00
slice-windows-no-bounds-check.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice_as_from_ptr_range.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
some-abis-do-extend-params-to-32-bits.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
some-global-nonnull.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
sparc-struct-abi.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
split-lto-unit.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
sroa-fragment-debuginfo.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
sse42-implies-crc32.rs Fix codegen tests 2024-08-07 00:41:48 -04:00
stack-probes-inline.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
stack-protector.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
static-relocation-model-msvc.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
staticlib-external-inline-fns.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
step_by-overflow-checks.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
stores.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
string-push.rs Speed up String::push and String::insert 2025-04-09 13:06:10 +03:00
swap-large-types.rs Ensure swap_nonoverlapping is really always untyped 2025-04-09 09:09:37 -07:00
swap-small-types.rs skip tests/codegen/swap-small-types when debug assertions are on 2025-04-09 10:44:49 -07:00
target-cpu-on-functions.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
target-feature-inline-closure.rs Fix target-feature inline test to be less flaky 2025-03-06 19:56:21 +00:00
target-feature-overrides.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
terminating-catchpad.rs Generate correct terminate block under Wasm EH 2025-02-06 18:21:13 +03:00
thread-local.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
tied-features-strength.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
to_vec.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
trailing_zeros.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
transmute-optimized.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
transmute-scalar.rs Emit trunc nuw for unchecked shifts and to_immediate_scalar 2025-02-19 11:36:52 -08:00
try_question_mark_nop.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
tune-cpu-on-functions.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
tuple-layout-opt.rs Fix test expectations for 32bit x86 2024-10-19 13:09:21 +00:00
ub-checks.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
unchecked-float-casts.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
unchecked_shifts.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
uninhabited-transparent-return-abi.rs tests: fix up new test for nocapture -> capture(none) change 2025-02-25 17:46:05 -05:00
uninit-consts.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
uninit-repeat-in-aggregate.rs Lower to a memset(undef) when Rvalue::Repeat repeats uninit 2025-03-19 23:57:49 -04:00
union-abi.rs Emit trunc nuw for unchecked shifts and to_immediate_scalar 2025-02-19 11:36:52 -08:00
unwind-and-panic-abort.rs Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
unwind-extern-exports.rs Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
unwind-extern-imports.rs Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
unwind-landingpad-cold.rs Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
unwind-landingpad-inline.rs Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
used_with_arg.rs
var-names.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-as-ptr.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-calloc.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
vec-in-place.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-iter-collect-len.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-iter.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-len-invariant.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-optimizes-away.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
vec-reserve-extend.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-shrink-panik.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec-with-capacity.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec_pop_push_noop.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
vecdeque-drain.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vecdeque-nonempty-get-no-panic.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vecdeque_no_panic.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vecdeque_pop_push.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
virtual-call-attrs-issue-137646.rs Don't infer unwinding of virtual calls based on the function attributes 2025-02-27 12:58:18 +08:00
virtual-function-elimination-32bit.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
virtual-function-elimination.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vtable-loads.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vtable-upcast.rs remove feature(trait_upcasting) from tests and bless them 2025-02-06 23:44:23 +01:00
wasm_casts_trapping.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
wasm_exceptions.rs Fix tests/codegen/wasm_exceptions 2025-01-28 19:10:26 +03:00
zip.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
zst-offset.rs Ban non-array SIMD 2024-09-09 19:39:43 -07:00

The files here use the LLVM FileCheck framework, documented at https://llvm.org/docs/CommandGuide/FileCheck.html.

One extension worth noting is the use of revisions as custom prefixes for FileCheck. If your codegen test has different behavior based on the chosen target or different compiler flags that you want to exercise, you can use a revisions annotation, like so:

// revisions: aaa bbb
// [bbb] compile-flags: --flags-for-bbb

After specifying those variations, you can write different expected, or explicitly unexpected output by using <prefix>-SAME: and <prefix>-NOT:, like so:

// CHECK: expected code
// aaa-SAME: emitted-only-for-aaa
// aaa-NOT:                        emitted-only-for-bbb
// bbb-NOT:  emitted-only-for-aaa
// bbb-SAME:                       emitted-only-for-bbb