make `Complex` ABI-compatible on sparc64 and powerpc64
tracking issue: https://github.com/rust-lang/rust/issues/154023
Make the ABI for `Complex` match C for two slightly more involved targets.
For Sparc64 the implementation matches GCC and Clang 24 and up. In https://github.com/llvm/llvm-project/pull/215015 a bug with how small complex numbers are passed was fixed.
For powerpc64 we match Clang exactly (and Clang is compatible with GCC for this target).
cc @beetrees @Gelbpunkt
sanitizers: Implement support for the sanitize ignorelist
The sanitize ignorelist gives central controls over which functions, files, etc. should be ignored and not sanitized. It is a common file format for clang and explained here:
https://clang.llvm.org/docs/SanitizerSpecialCaseList.html. This change adds support for this list in Rust as well.
r? @rcvalle
Pass -Z merge-functions=disabled in tests/codegen-llvm/intrinsics/unchecked_math.rs
Otherwise e.g. `@unchecked_add_unsigned` and `@unchecked_add_signed` get merged after https://github.com/llvm/llvm-project/pull/220015, breaking the test's expectations.
The sanitize ignorelist gives central controls over which functions,
files, etc. should be ignored and not sanitized. It is a common file
format for clang and explained here:
https://clang.llvm.org/docs/SanitizerSpecialCaseList.html. This change
adds support for this list in Rust as well.
Test itanium mangling of `f16` and `f128`
And fix the string that is used for `f128` on powerpc targets, where the standard `"g"` is already taken by `__ibm128`.
In clang
bd5b1f58ae/clang/lib/Basic/Targets/PPC.h (L362-L363)
```c
const char *getFloat128Mangling() const override { return "u9__ieee128"; }
const char *getIbm128Mangling() const override { return "g"; }
```
and GCC
fc54ab94ad/gcc/config/rs6000/rs6000.cc (L20795-L20801)
```c
if (SCALAR_FLOAT_TYPE_P (type) && FLOAT128_IBM_P (TYPE_MODE (type)))
return "g";
if (SCALAR_FLOAT_TYPE_P (type) && FLOAT128_IEEE_P (TYPE_MODE (type)))
return "u9__ieee128";
```
From what i can tell this is not really testable for powerpc at the moment because CFI is not supported on powerpc.
r? tgross35
volatile: allow accesses to non-AM memory to trap
Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/610 by saying that yes, volatile accesses may trap. This also fixes what I believe to be the last case of "time-traveling UB" we have in Rust: with this change, UB always fully sequenced wrt observable events (I/O and volatile accesses). UB can still travel around unobservable events such as non-volatile memory accesses.
For writes, LLVM has already implemented the new semantics for a long time. For reads, LLVM only recently implemented the "may trap" semantics with LLVM 23. We still allow compiling rustc with older versions of LLVM. To (hopefully) prevent old LLVM from screwing this up with optimizations, this PR makes the backend emit an inline asm block *without* `willreturn`, which should prevent optimizations that break programs where a volatile load traps.
Cc @rust-lang/opsem @rust-lang/wg-llvm
Rework `next_power_of_two` to always be `1 << …`
r? @clarfonthey
Who accidentally nerd-sniped me by mentioning rust-lang/rust#161069
This obviates that PR by reworking the `(checked_)next_power_of_two` logic to calculate the necessary exponent e, then return 2ᵉ, so it's structurally obvious from the IR -- the `shl nuw 1, …` instruction -- that it's always a power of two.
As always, the reason this is tricky is because shifts don't work for `<< Self::BITS`. The previous code handled that by checking `self <= 1` first, and thus doing a `-1 >> n` where `n < BITS`. This code instead flips the check: it looks up-front for a value that will wrap (an input above `1 << (BITS - 1)`) and thus by excluding those cases the calculated `1 << n` always has `n < BITS`. And the codegen tests show that, without needing any `llvm.assume`s, LLVM can take advantage of it to do things like rewriting `%` to masking. Plus the overflow check optimizes out for constrained inputs like slice lengths.
Rollup of 2 pull requests
Successful merges:
- rust-lang/rust#161692 (Allow Unpin impls for local extern type)
- rust-lang/rust#161886 (compiler: Make +fix-cortex-a53-835769 a default feature for aarch64 fuchsia)
compiler: Make +fix-cortex-a53-835769 a default feature for aarch64 fuchsia
This matches the default target features for aarch64 fuchsia emitted by clang.
compiler: Allow safestack to be togglable via #[sanitize(safestack = "...")]
Since safestack is a sanitizer, it should be possible to allow enabling/disabling it on functions like we do with the other sanitizers. It's likely that when adding the `#[sanitize(...)]` support for the other ones that safestack was just missed, so this makes safestack follow suite. It was also suggested in https://github.com/rust-lang/rust/pull/159873 that we just disable safestack this way for a specific test where we should check stack protector instrumentation.
Put data segment in specified section with link_section on wasm
This is the normal behavior on other targets, but previously on wasm the data segment would be in the default section and instead a custom section with the given name would be added to the wasm module.
Fixes https://github.com/rust-lang/rust/issues/146538
r? alexcrichton
This is the normal behavior on other targets, but previously on wasm the
data segment would be in the default section and instead a custom
section with the given name would be added to the wasm module.
Add codegen test for static table search loop unrolling
Adds a test for reported case in rust-lang/rust#44041. The follow up case in that issue is still open so this does not close it
Pass LargeDataThreshold to LLVM module IR
Before, LargeDataThreshold was only set via `LLVMRustCreateTargetMachine`. When LTO is enabled, this information is required to be passed into the generated LLVM module IR files since the LTO linker spins up its own TargetMachine and otherwise has no knowledge of the LargeDataThreshold.
Currently, `-Z large-data-threshold` has no affect at all when compiling with LTO.
This commit makes sure that if `-Z large-data-threshold` is passed and not 0, it is preserved and stored into the generated LLVM IR.
Before, LargeDataThreshold was only set via `LLVMRustCreateTargetMachine`.
When LTO is enabled, this information is required to be passed into the
generated LLVM module IR files since the LTO linker spins up its own
TargetMachine and otherwise has no knowledge of the LargeDataThreshold.
Currently, `-Z large-data-threshold` has no affect at all when compiling
with LTO.
This commit makes sure that if `-Z large-data-threshold` is passed and
not 0, it is preserved and stored into the generated LLVM IR.
add `Complex<T>` layout tests for straightforward targets
tracking issue: https://github.com/rust-lang/rust/issues/154023
Best reviewed commit-by-commit.
This PR does two things
- it updates and enables the CHECK lines for targets where rust already matches the ABI of complex numbers. The original check lines are what `clang` emits. Rust often specifies the same signature slightly differently, but those differences are just cosmetic, e.g. `{ half, half }` versus `[2 x half]`.
- adds some custom logic for complex numbers on `s390x`, so that they match `clang` and `gcc` for that target.
I've validated this extensively with `abi-cafe`. But also, this is just locking in the status-quo for an unstable feature. So, I'm not really looking for someone to pore over every line of the diff, just a coarse scan to see if anything odd jumps out. We have automated ways of checking that our logic is actually correct.