rust/tests/codegen
Jacob Pratt 575405161f
Rollup merge of #134090 - veluca93:stable-tf11, r=oli-obk
Stabilize target_feature_11

# Stabilization report

This is an updated version of https://github.com/rust-lang/rust/pull/116114, which is itself a redo of https://github.com/rust-lang/rust/pull/99767. Most of this commit and report were copied from those PRs. Thanks ```@LeSeulArtichaut``` and ```@calebzulawski!```

## Summary
Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot *generally* be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

Moreover, once https://github.com/rust-lang/rust/pull/135504 is merged, they can be converted to safe function pointers in a context in which calling them is safe:

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() -> fn() {
    // Converting `avx2` to fn() is a compilation error here.
    avx2
}

#[target_feature(enable = "avx2")]
fn bar() -> fn() {
    // `avx2` coerces to fn() here
    avx2
}
```

See the section "Closures" below for justification of this behaviour.

## Test cases
Tests for this feature can be found in [`tests/ui/target_feature/`](f6cb952dc1/tests/ui/target-feature).

## Edge cases
### Closures
 * [target-feature 1.1: should closures inherit target-feature annotations? #73631](https://github.com/rust-lang/rust/issues/73631)

Closures defined inside functions marked with #[target_feature] inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```
This means that in order to call a function with #[target_feature], you must guarantee that the target-feature is available while the function, any closures defined inside it, as well as any safe function pointers obtained from target-feature functions inside it, execute.

This is usually ensured because target features are assumed to never disappear, and:
- on any unsafe call to a `#[target_feature]` function, presence of the target feature is guaranteed by the programmer through the safety requirements of the unsafe call.
- on any safe call, this is guaranteed recursively by the caller.

If you work in an environment where target features can be disabled, it is your responsibility to ensure that no code inside a target feature function (including inside a closure) runs after this (until the feature is enabled again).

**Note:** this has an effect on existing code, as nowadays closures do not inherit features from the enclosing function, and thus this strengthens a safety requirement. It was originally proposed in #73631 to solve this by adding a new type of UB: “taking a target feature away from your process after having run code that uses that target feature is UB” .
This was motivated by userspace code already assuming in a few places that CPU features never disappear from a program during execution (see i.e. 2e29bdf908/crates/std_detect/src/detect/arch/x86.rs); however, concerns were raised in the context of the Linux kernel; thus, we propose to relax that requirement to "causing the set of usable features to be reduced is unsafe; when doing so, the programmer is required to ensure that no closures or safe fn pointers that use removed features are still in scope".

* [Fix #[inline(always)] on closures with target feature 1.1 #111836](https://github.com/rust-lang/rust/pull/111836)

Closures accept `#[inline(always)]`, even within functions marked with `#[target_feature]`. Since these attributes conflict, `#[inline(always)]` wins out to maintain compatibility.

### ABI concerns
* [The extern "C" ABI of SIMD vector types depends on target features #116558](https://github.com/rust-lang/rust/issues/116558)

The ABI of some types can change when compiling a function with different target features. This could have introduced unsoundness with target_feature_11, but recent fixes (#133102, #132173) either make those situations invalid or make the ABI no longer dependent on features. Thus, those issues should no longer occur.

### Special functions
The `#[target_feature]` attribute is forbidden from a variety of special functions, such as main, current and future lang items (e.g. `#[start]`, `#[panic_handler]`), safe default trait implementations and safe trait methods.

This was not disallowed at the time of the first stabilization PR for target_features_11, and resulted in the following issues/PRs:
* [`#[target_feature]` is allowed on `main` #108645](https://github.com/rust-lang/rust/issues/108645)
* [`#[target_feature]` is allowed on default implementations #108646](https://github.com/rust-lang/rust/issues/108646)
* [#[target_feature] is allowed on #[panic_handler] with target_feature 1.1 #109411](https://github.com/rust-lang/rust/issues/109411)
* [Prevent using `#[target_feature]` on lang item functions #115910](https://github.com/rust-lang/rust/pull/115910)

## Documentation
 * Reference: [Document the `target_feature_11` feature reference#1181](https://github.com/rust-lang/reference/pull/1181)
---

cc tracking issue https://github.com/rust-lang/rust/issues/69098
cc ```@workingjubilee```
cc ```@RalfJung```
r? ```@rust-lang/lang```
2025-02-12 20:09:56 -05:00
..
asm tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
auxiliary Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
avr tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
bounds-checking Simplify the GEP instruction for index 2024-12-15 19:01:45 +08:00
cffi more asm! -> naked_asm! in tests 2024-10-06 18:12:25 +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 tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
dllimports Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
enum tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
float Fix tests/codegen/float/f128 2025-01-28 19:10:24 +03: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
issues tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
lib-optimizations tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
loongarch-abi tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
macos tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
meta-filecheck compiletest: don't register MSVC/NONMSVC FileCheck prefixes 2024-12-19 20:36:51 +08:00
naked-fn tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
repr tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
riscv-abi tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
sanitizer Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle 2024-11-23 20:19:51 +08:00
simd tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
simd-intrinsic Fix SIMD codegen tests on LLVM 20 2025-01-27 15:11:59 +01: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 Update test expectations to accept LLVM 'initializes' attribute 2024-11-25 15:30:35 +01:00
aarch64-struct-align-128.rs Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
abi-efiapi.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
abi-sysv64.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
abi-win64-zst.rs on Windows, consistently pass ZST by-ref 2025-01-12 13:32:36 +01:00
abi-x86_64_sysv.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
abi-x86-interrupt.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00: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 Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
align-byval-vector.rs Ban non-array SIMD 2024-09-09 19:39:43 -07:00
align-byval.rs tests: Remove test for wrong wasm codegen 2024-09-18 12:28:55 -07:00
align-enum.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
align-fn.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-clone.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
array-cmp.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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
async-closure-debug.rs Stabilize async closures 2024-12-13 00:04:56 +00:00
async-fn-debug-awaitee-field.rs Explicitly register MSVC/NONMSVC revisions for some codegen tests 2024-12-19 20:36:51 +08:00
async-fn-debug-msvc.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
async-fn-debug.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00: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
autodiff.rs move second opt run to lto phase and cleanup code 2025-02-10 01:35:22 -05: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-uninit-bytes.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
bpf-alu32.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
branch-protection-old-llvm.rs tests: use max-llvm-major-version instead of ignore-llvm-version range like N - 99 2024-11-14 17:44:54 +08:00
branch-protection.rs rustc_codegen_llvm: Add a new 'pc' option to branch-protection 2024-10-31 11:59:17 +00:00
call-llvm-intrinsics.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
call-metadata.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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
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_as_copy.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
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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
comparison-operators-2-tuple.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
comparison-operators-newtype.rs Set signext or zeroext for integer arguments on RISC-V 2024-10-23 04:42:03 +02:00
const_scalar_pair.rs Fix tests and bless 2024-04-24 13:12:33 +01:00
const-array.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
const-vector.rs Ban non-array SIMD 2024-09-09 19:39:43 -07: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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
dealloc-no-unwind.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Explicitly register MSVC/NONMSVC revisions for some codegen tests 2024-12-19 20:36:51 +08: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 Explicitly register MSVC/NONMSVC revisions for some codegen tests 2024-12-19 20:36:51 +08: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 Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02: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_codegen_private_const_fn_only_used_in_const_eval.rs Also support generic constants 2024-06-05 15:40:11 +00:00
dont-shuffle-bswaps.rs tests: simplify dont-shuffle-bswaps test 2025-02-11 13:41:26 -08: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
emscripten-catch-unwind-wasm-eh.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Add -Zfixed-x18 2024-05-03 14:32:08 +02:00
float_math.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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 Add missing module flags for function-return=thunk-extern 2024-09-25 15:53:53 +02: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 Simplify the GEP instruction for index 2024-12-15 19:01:45 +08:00
gpu-kernel-abi.rs Add gpu-kernel calling convention 2025-01-16 00:26:55 +01: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 Windows x86: Change i128 to return via the vector ABI 2025-01-27 12:12:59 +00:00
infallible-unwrap-in-opt-z.rs Ignore less tests in debug builds 2024-02-23 18:04:01 -05: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 Rework MIR inlining debuginfo so function parameters show up in debuggers. 2024-08-12 19:20:00 -07: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 tests: use max-llvm-major-version instead of ignore-llvm-version range like N - 99 2024-11-14 17:44:54 +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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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 llvm: Tolerate propagated range metadata 2024-10-16 18:38:26 +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_section.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
link-dead-code.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
llvm_module_flags.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
llvm-ident.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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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_zst_stores.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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
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 fix the naked-asan test 2024-12-10 21:41:05 +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
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 [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +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
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 Also generate undef scalars and scalar pairs 2025-01-21 08:22:15 +00: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 Rename core_pattern_type and core_pattern_types lib feature gates to pattern_type_macro 2024-12-04 16:16:24 +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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
precondition-checks.rs Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10:00
ptr-arithmetic.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
ptr-read-metadata.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
range_to_inclusive.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
range-attribute.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
README.md Move /src/test to /tests 2023-01-11 09:32:08 +00:00
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/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Always specify llvm_abiname for RISC-V targets 2024-10-17 02:07:02 +01: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_from_ptr_range.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 more tests 2025-01-21 08:27:30 +00:00
slice-is-ascii.rs Add is_ascii function optimized for x86-64 for [u8] 2024-11-06 02:22:00 -05: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-iter-nonnull.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-reverse.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
slice-windows-no-bounds-check.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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Run rustfmt on tests/codegen/. 2024-05-31 15:56:43 +10: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
swap-large-types.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
swap-small-types.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 Stabilize target_feature_11 2025-01-27 23:44:47 +01:00
target-feature-overrides.rs ABI-required target features: warn when they are missing in base CPU (rather than silently enabling them) 2025-01-28 04:40:42 +01: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 ABI-required target features: warn when they are missing in base CPU (rather than silently enabling them) 2025-01-28 04:40:42 +01: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 Set signext or zeroext for integer arguments on RISC-V 2024-10-23 04:42:03 +02:00
try_question_mark_nop.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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_shifts.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
uninit-consts.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
union-abi.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -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 Move /src/test to /tests 2023-01-11 09:32:08 +00:00
var-names.rs tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08:00
vec_pop_push_noop.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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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 tests/codegen: use -Copt-level=3 instead of -O 2025-02-11 13:41:35 -08: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
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
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
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