rust/tests/assembly
Trevor Gross c117ebefd2
Rollup merge of #140920 - RalfJung:target-feature-unification, r=nnethercote,WaffleLapkin
Extract some shared code from codegen backend target feature handling

There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in `rustc_codegen_ssa`.

The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the `-Ctarget-feature` flag to populate `cfg(target_feature)`. That seems odd, since the `-Ctarget-feature` flag is used to populate the return value of `global_gcc_features` which controls the target features actually used by GCC. ``@GuillaumeGomez`` ``@antoyo`` is there a reason `target_config` ignores `-Ctarget-feature` but `global_gcc_features`  does not? The second commit also cleans up a bunch of unneeded complexity added in https://github.com/rust-lang/rust/pull/135927.

The third commit extracts some shared logic out of the functions that populate `cfg(target_feature)` and the backend target feature set, respectively. This one actually has some slight functional changes:
- Before, with `-Ctarget-feature=-feat`, if there is some other feature `x` that implies `feat` we would *not* add `-x` to the backend target feature set. Now, we do. This fixes rust-lang/rust#134792.
- The logic that removes `x` from `cfg(target_feature)` in this case also changed a bit, avoiding a large number of calls to the (uncached) `sess.target.implied_target_features` (if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs before `tcx` so we can't use that...
- Previously, if feature "a" implied "b" and "b" was unstable, then using `-Ctarget-feature=+a` would also emit a warning about `b`. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway.

The fourth commit increases consistency of the GCC backend with the LLVM backend.

The last commit does some further cleanup:
- Get rid of RUSTC_SPECIAL_FEATURES. It was only needed for s390x "backchain", but since LLVM 19 that is always a regular target feature so we don't need this hack any more. The hack also has various unintended side-effects so we don't want to keep it. Fixes https://github.com/rust-lang/rust/issues/142412.
- Move RUSTC_SPECIFIC_FEATURES handling into the shared parse_rust_feature_flag helper so all consumers of `-Ctarget-feature` that only care about actual target features (and not "crt-static") have it. Previously, we actually set `cfg(target_feature = "crt-static")` twice: once in the backend target feature logic, and once specifically for that one feature. IIUC, some targets are meant to ignore `-Ctarget-feature=+crt-static`, it seems like before this PR that flag still incorrectly enabled `cfg(target_feature = "crt-static")` (but I didn't test this).
- Move fixed_x18 handling together with retpoline handling.
- Forbid setting fixed_x18 as a regular target feature, even unstably. It must be set via the `-Z` flag.

``@bjorn3`` I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :)

Cc ``@workingjubilee``
2025-06-20 02:50:38 -04:00
..
asm Add f16 inline asm support for LoongArch 2025-06-14 09:39:30 +08:00
auxiliary Stabilize -Zdwarf-version as -Cdwarf-version 2025-04-14 21:26:41 -05:00
compiletest-self-test tests/assembly: add minicore compiletest self-test 2024-10-31 18:20:11 +08:00
libs add regression test for 140207 2025-05-11 14:29:24 +02:00
naked-functions add #[align] attribute 2025-06-18 12:37:08 +02:00
nvptx-kernel-abi tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
sanitizer/kcfi KCFI: Add KCFI arity indicator support 2025-04-05 04:05:04 +00:00
simd tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
stack-protector Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
targets Add new Tier-3 targets: loongarch32-unknown-none* 2025-06-06 08:19:38 +08:00
aarch64-pointer-auth.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
aarch64-xray.rs Add compiler tests for xray 2025-05-26 00:39:23 +08:00
align_offset.rs Run rustfmt on tests/assembly/. 2024-05-30 16:15:46 +10:00
breakpoint.rs Add core::arch::breakpoint and test 2024-12-02 23:56:24 -08:00
closure-inherit-target-feature.rs x86-sse2 ABI: use SSE registers for floats and SIMD 2025-02-18 16:11:41 +01:00
cmse.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
cstring-merging.rs Make C string merging test work on MIPS 2025-04-17 16:08:22 +02:00
dwarf-mixed-versions-lto.rs Stabilize -Zdwarf-version as -Cdwarf-version 2025-04-14 21:26:41 -05:00
dwarf4.rs Stabilize -Zdwarf-version as -Cdwarf-version 2025-04-14 21:26:41 -05:00
dwarf5.rs Stabilize -Zdwarf-version as -Cdwarf-version 2025-04-14 21:26:41 -05:00
is_aligned.rs Run rustfmt on tests/assembly/. 2024-05-30 16:15:46 +10:00
issue-83585-small-pod-struct-equality.rs Fix tests for 32 bits targets 2024-06-11 07:45:16 +00:00
manual-eq-efficient.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
niche-prefer-zero.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-arch-default.rs NVPTX: Enable previously disabled tests 2024-03-11 13:35:58 +01:00
nvptx-arch-emit-asm.rs NVPTX: Enable previously disabled tests 2024-03-11 13:35:58 +01:00
nvptx-arch-link-arg.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-arch-target-cpu.rs NVPTX: Enable previously disabled tests 2024-03-11 13:35:58 +01:00
nvptx-atomics.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-c-abi-arg-v7.rs tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
nvptx-c-abi-ret-v7.rs tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
nvptx-internalizing.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-linking-binary.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-linking-cdylib.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nvptx-safe-naming.rs NVPTX: Enable previously disabled tests 2024-03-11 13:35:58 +01:00
panic-no-unwind-no-uwtable.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
panic-unwind-no-uwtable.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
pic-relocation-model.rs Apply ABI attributes on return types in rustc_codegen_cranelift 2025-06-12 00:47:01 +01:00
pie-relocation-model.rs Apply ABI attributes on return types in rustc_codegen_cranelift 2025-06-12 00:47:01 +01:00
powerpc64-struct-abi.rs Use explicit cpu in some asm and codegen tests. 2025-03-19 19:45:46 +01:00
riscv-float-struct-abi.rs Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00
riscv-soft-abi-with-float-features.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
rust-abi-arg-attr.rs tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
s390x-backchain-toggle.rs various minor target feature cleanups 2025-06-19 10:50:03 +09:00
s390x-vector-abi.rs tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
simd-bitmask.rs make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
simd-intrinsic-gather.rs update/bless tests 2025-04-06 21:41:47 +02:00
simd-intrinsic-mask-load.rs update/bless tests 2025-04-06 21:41:47 +02:00
simd-intrinsic-mask-reduce.rs update/bless tests 2025-04-06 21:41:47 +02:00
simd-intrinsic-mask-store.rs update/bless tests 2025-04-06 21:41:47 +02:00
simd-intrinsic-scatter.rs update/bless tests 2025-04-06 21:41:47 +02:00
simd-intrinsic-select.rs make abi_unsupported_vector_types a hard error 2025-04-20 11:34:56 +02:00
slice-is_ascii.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
small_data_threshold.rs tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
sparc-struct-abi.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
stack-probes.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
static-relocation-model.rs Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
strict_provenance.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
target-feature-multiple.rs tests: use minicore more 2025-02-24 09:26:54 +00:00
wasm_exceptions.rs Fix wasm_exceptions test 2024-06-19 21:26:48 +01:00
x86-return-float.rs tests: account for CFI directives in tests/assembly/x86-return-float.rs 2025-04-23 17:11:49 +08:00
x86_64-array-pair-load-store-merge.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
x86_64-bigint-helpers.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
x86_64-cmp.rs Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics 2025-03-06 22:29:05 +08:00
x86_64-floating-point-clamp.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
x86_64-fortanix-unknown-sgx-lvi-generic-load.rs Run rustfmt on tests/assembly/. 2024-05-30 16:15:46 +10:00
x86_64-fortanix-unknown-sgx-lvi-generic-ret.rs Run rustfmt on tests/assembly/. 2024-05-30 16:15:46 +10:00
x86_64-fortanix-unknown-sgx-lvi-inline-assembly.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
x86_64-function-return.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
x86_64-no-jump-tables.rs tests/assembly: use -Copt-level=3 instead of -O 2025-02-08 19:02:32 -08:00
x86_64-sse_crc.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
x86_64-typed-swap.rs Ensure swap_nonoverlapping is really always untyped 2025-04-09 09:09:37 -07:00
x86_64-windows-float-abi.rs tests: adjust expectation for f128 abi on Windows 2025-04-10 15:28:56 -04:00
x86_64-windows-i128-abi.rs x86_win64 ABI: do not use xmm0 with softfloat ABI 2025-02-19 08:41:19 +01:00
x86_64-xray.rs Add compiler tests for xray 2025-05-26 00:39:23 +08:00