rust/tests/codegen
Jacob Pratt 4a1d0cd1bd
Rollup merge of #139718 - folkertdev:unsafe-attributes-earlier-editions, r=fmease
enforce unsafe attributes in pre-2024 editions by default

New unsafe attributes should emit an error when used without the `unsafe(...)` in all editions.

The `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions. The only attributes for which this change is relevant right now are `#[ffi_const]` and `#[ffi_pure]`.

This change is required for making `#[unsafe(naked)]` sound in pre-2024 editions.
2025-04-13 23:57:40 -04: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
avr update/bless tests 2025-04-06 21:41:47 +02:00
bounds-checking
cffi error on unsafe attributes in pre-2024 editions 2025-04-13 01:22:59 +02:00
compiletest-self-test
cross-crate-inlining
debug-accessibility
debuginfo-proc-macro Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
dllimports
enum Address PR feedback 2025-04-07 18:12:06 -07: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
instrument-coverage
instrument-xray
intrinsics Move select_unpredictable to the hint module 2025-04-13 01:34:25 +01:00
issues Auto merge of #139430 - scottmcm:polymorphic-array-into-iter, r=cuviper 2025-04-11 23:21:31 +00:00
lib-optimizations
loongarch-abi
macos
meta-filecheck
naked-fn naked functions: on windows emit .endef without the symbol name 2025-03-11 00:27:32 +01:00
non-terminate
patchable-function-entry
remap_path_prefix Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
repr
riscv-abi
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 remove most simd_ intrinsic declaration in tests 2025-02-27 12:22:59 +01:00
src-hash-algorithm
unwind-abis
aarch64-softfloat.rs
aarch64-struct-align-128.rs
abi-efiapi.rs
abi-main-signature-16bit-c-int.rs
abi-main-signature-32bit-c-int.rs
abi-repr-ext.rs
abi-sysv64.rs
abi-win64-zst.rs
abi-x86-interrupt.rs
abi-x86-sse.rs
abi-x86_64_sysv.rs
addr-of-mutate.rs
adjustments.rs
align-byval-alignment-mismatch.rs
align-byval-vector.rs
align-byval.rs
align-enum.rs
align-fn.rs
align-offset.rs
align-struct.rs
alloc-optimisation.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
amdgpu-addrspacecast.rs
array-clone.rs
array-cmp.rs Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
array-codegen.rs
array-equality.rs
array-from_fn.rs
array-map.rs
array-optimized.rs
array-repeat.rs
ascii-char.rs
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
atomicptr.rs
autovectorize-f32x4.rs
bigint-helpers.rs
binary-heap-peek-mut-pop-no-panic.rs
binary-search-index-no-bound-check.rs
bool-cmp.rs
box-default-debug-copies.rs
box-uninit-bytes.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
bpf-alu32.rs
branch-protection.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
call-llvm-intrinsics.rs
cast-optimized.rs
cast-target-abi.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
catch-unwind.rs
cdylib-external-inline-fns.rs
cf-protection.rs
cfguard-checks.rs
cfguard-disabled.rs
cfguard-nochecks.rs
cfguard-non-msvc.rs
char-ascii-branchless.rs
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
checked_math.rs
clone-shims.rs
clone_as_copy.rs Remove unsound-mir-opts for simplify_aggregate_to_copy 2025-04-03 21:59:43 +08:00
codemodels.rs
coercions.rs
cold-call-declare-and-call.rs
common_prim_int_ptr.rs
comparison-operators-2-struct.rs
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
const-array.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
const-vector.rs
const_scalar_pair.rs
constant-branch.rs
consts.rs
coroutine-debug-msvc.rs
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
debug-column-msvc.rs
debug-column.rs
debug-compile-unit-path.rs
debug-fndef-size.rs
debug-limited.rs
debug-line-directives-only.rs
debug-line-tables-only.rs
debug-linkage-name.rs
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
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
deduced-param-attrs.rs
default-requires-uwtable.rs
default-visibility.rs
direct-access-external-data.rs
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
drop-in-place-noalias.rs
drop.rs
dst-offset.rs
dst-vtable-align-nonzero.rs
dst-vtable-size-range.rs
ehcontguard_disabled.rs
ehcontguard_enabled.rs
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
error-provide.rs
export-no-mangle.rs
external-no-mangle-fns.rs
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
fastcall-inreg.rs
fatptr.rs
fewer-names.rs
fixed-x18.rs
float_math.rs Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
fn-impl-trait-self.rs
force-frame-pointers.rs
force-no-unwind-tables.rs
force-unwind-tables.rs
frame-pointer.rs
function-arguments-noopt.rs
function-arguments.rs
function-return.rs
gdb_debug_script_load.rs
generic-debug.rs
gep-index.rs
gpu-kernel-abi.rs
i128-wasm32-callconv.rs
i128-x86-align.rs
i128-x86-callconv.rs
infallible-unwrap-in-opt-z.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
inherit_overflow.rs
inline-always-works-always.rs
inline-debuginfo.rs
inline-function-args-debug-info.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
inline-hint.rs
instrument-mcount.rs
integer-cmp.rs Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics 2025-03-06 22:29:05 +08:00
integer-overflow.rs
internalize-closures.rs
intrinsic-no-unnamed-attr.rs update/bless tests 2025-04-06 21:41:47 +02:00
is_val_statically_known.rs
issue-97217.rs
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
lifetime_start_end.rs
link-dead-code.rs
link_section.rs Avoid wrapping constant allocations in packed structs when not necessary 2025-03-28 09:19:57 +00:00
llvm-ident.rs
llvm_module_flags.rs
loads.rs
local-generics-in-exe-internalized.rs
lto-removes-invokes.rs
mainsubprogram.rs
match-optimized.rs
match-optimizes-away.rs Don't alloca just to look at a discriminant 2025-03-12 00:56:43 -07:00
match-unoptimized.rs
maybeuninit-rvo.rs
mem-replace-big-type.rs
mem-replace-simple-type.rs
merge-functions.rs
method-declaration.rs
min-function-alignment.rs
mir-aggregate-no-alloca.rs
mir-inlined-line-numbers.rs
mir_zst_stores.rs
move-before-nocapture-ref-arg.rs
move-operands.rs
naked-asan.rs
no-alloca-inside-if-false.rs
no-assumes-on-casts.rs
no-dllimport-w-cross-lang-lto.rs
no-jump-tables.rs
no-plt.rs
no-redundant-item-monomorphization.rs
no_builtins-at-crate.rs
noalias-box-off.rs
noalias-box.rs
noalias-flag.rs
noalias-freeze.rs
noalias-refcell.rs
noalias-rwlockreadguard.rs
noalias-unpin.rs
noreturn-uninhabited.rs
noreturnflag.rs
nounwind.rs
nrvo.rs
optimize-attr-1.rs
option-as-slice.rs
option-niche-eq.rs
overaligned-constant.rs
packed.rs
panic-abort-windows.rs
panic-in-drop-abort.rs
panic-unwind-default-uwtable.rs
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
pgo-counter-bias.rs
pgo-instrumentation.rs
pic-relocation-model.rs
pie-relocation-model.rs
placement-new.rs
powerpc64le-struct-align-128.rs
precondition-checks.rs
ptr-arithmetic.rs
ptr-read-metadata.rs
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
README.md
refs.rs
reg-struct-return.rs
regparm-inreg.rs
repeat-trusted-len.rs
riscv-target-abi.rs
rust-abi-arch-specific-adjustment.rs
s390x-simd.rs
scalar-pair-bool.rs
set-discriminant-invalid.rs
skip-mono-inside-if-false.rs
slice-as_chunks.rs
slice-indexing.rs
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
slice-iter-len-eq-zero.rs
slice-iter-nonnull.rs
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
slice-position-bounds-check.rs
slice-ref-equality.rs
slice-reverse.rs
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
slice_as_from_ptr_range.rs
some-abis-do-extend-params-to-32-bits.rs
some-global-nonnull.rs
sparc-struct-abi.rs
split-lto-unit.rs
sroa-fragment-debuginfo.rs
sse42-implies-crc32.rs
stack-probes-inline.rs
stack-protector.rs
static-relocation-model-msvc.rs
staticlib-external-inline-fns.rs
step_by-overflow-checks.rs
stores.rs
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
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
terminating-catchpad.rs
thread-local.rs
tied-features-strength.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
to_vec.rs
trailing_zeros.rs
transmute-optimized.rs
transmute-scalar.rs
try_question_mark_nop.rs replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
tune-cpu-on-functions.rs
tuple-layout-opt.rs
ub-checks.rs
unchecked-float-casts.rs
unchecked_shifts.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
uninhabited-transparent-return-abi.rs
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
unwind-and-panic-abort.rs
unwind-extern-exports.rs
unwind-extern-imports.rs
unwind-landingpad-cold.rs
unwind-landingpad-inline.rs
used_with_arg.rs
var-names.rs
vec-as-ptr.rs
vec-calloc.rs Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
vec-in-place.rs
vec-iter-collect-len.rs
vec-iter.rs
vec-len-invariant.rs
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
vec-shrink-panik.rs
vec-with-capacity.rs
vec_pop_push_noop.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
vecdeque-drain.rs
vecdeque-nonempty-get-no-panic.rs
vecdeque_no_panic.rs
vecdeque_pop_push.rs
virtual-call-attrs-issue-137646.rs
virtual-function-elimination-32bit.rs
virtual-function-elimination.rs
vtable-loads.rs
vtable-upcast.rs
wasm_casts_trapping.rs
wasm_exceptions.rs
zip.rs
zst-offset.rs

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