Commit Graph

774 Commits

Author SHA1 Message Date
WANG Rui
41ae947f50 tests: Update f16b codegen test for LoongArch and RISC-V
Add target-specific revisions to the `f16b` codegen test to account for
LoongArch and RISC-V lowering `f16b` to LLVM `half` rather than `bfloat`.
2026-09-23 00:57:13 +08:00
bors
2699985190 Auto merge of #163119 - JonathanBrouwer:rollup-YdZQI8k, r=JonathanBrouwer
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#162948 (Set target-abi module flag for LoongArch targets)
 - rust-lang/rust#162600 (Make the last non-breaking box impl generalizations)
 - rust-lang/rust#163031 (Use newer `make` version when building GCC)
 - rust-lang/rust#163054 (Use verbose suggestion for method written as function)
 - rust-lang/rust#163073 (Expand docs on `rustc_abi::Variants`)
2026-09-21 16:30:27 +00:00
Jonathan Brouwer
7c0c8e0c4d Rollup merge of #162948 - heiher:loong-emit-target-abi, r=nikic
Set target-abi module flag for LoongArch targets

Like the earlier RISC-V fix (rust-lang/rust#123612), emit the "target-abi" module flag for LoongArch so that LTO correctly picks up the ABI.

This follows the recent LLVM change (llvm/llvm-project#223647) that relies on the module flag for proper TargetMachine / data-layout handling during LTO on LoongArch.
2026-09-21 17:34:09 +02:00
Jonathan Brouwer
e1b8be29ff Rollup merge of #160859 - Jamesbarford:feat/fb16-pt1, r=folkertdev,tgross35
`core::num::f16b` Rust's 16bit Brain Float

Implements the [RFC: f16b type](https://github.com/rust-lang/rfcs/pull/3983). Best reviewed commit by commit, happy to split into separate PRs if that is deemed easier to review. However the line count and surface area is, in my opinion, reasonably small.

Adds;
- ABI plumbing for the `f16b` along with `bfloat` lang item to work with LLVM, GCC is explicitly `unimplemented!(...)`
- `f16b` feature gate, page for `f16b` on libruscdoc and a `struct bf16` in `core::num`
- Tests
- Treat `f16b` as a scalar primitive for scalable vectors

Issues;
- [Tracking Issue](https://github.com/rust-lang/rust/issues/160630)
- [RFC](https://github.com/rust-lang/rfcs/pull/3983)
2026-09-21 15:19:23 +02:00
James Barford-Evans
e130380227 Update and write tests 2026-09-21 08:57:52 +01:00
malezjaa
3de0624444 Use r14 register name with LLVM 23+ 2026-09-20 14:30:18 +02:00
malezjaa
35ec478d1f Use x30 register name with LLVM 23+ 2026-09-20 14:14:56 +02:00
WANG Rui
ca8ee2fc33 Set target-abi module flag for LoongArch targets 2026-09-19 16:50:13 +08:00
Jonathan Brouwer
75e90b2129 Rollup merge of #162956 - beetrees:test-repr-c-struct, r=folkertdev
Add missing `#[repr(C)]` in UI, codegen and assembly tests

There are quite a few tests which omit the `#[repr(C)]` on structs that are then used in non-Rustic ABIs. I've gone through the tests in `ui/abi`, `ui/ffi`, `codegen-llvm` and `assembly-llvm` and added `#[repr(C)]` where it was missing. I also converted `#[allow(improper_ctypes{,_definitions})]` to `#[expect(improper_ctypes{,_definitions})]` where possible, and removed it where the lint no longer triggers.

I haven't done it in this PR, but I think it's worth making codegen and assembly tests deny warnings by default. With UI tests `improper_ctypes{,_definitions}` has to be either allowed or will show up in the output, meaning it should be fairly obvious to reviewers, but with codegen and assembly tests warnings just get ignored if the test passes.

Fixes rust-lang/rust#53858

r? @folkertdev
cc @RalfJung
2026-09-19 08:45:42 +02:00
Jonathan Brouwer
7baf1859a5 Rollup merge of #162924 - Jamesbarford:fix/remove-inline-attributes-at-callsite, r=saethlin
Remove applying inline attributes at the callsite

Following from our discussion and the currently open PR; https://github.com/rust-lang/rust/pull/162460, removing the blanket addition of inline attributes at the callsite, even without the `#[inline(always)]` changes, looks to now have negligible impact.
2026-09-19 08:45:35 +02:00
Jonathan Brouwer
40f4756668 Rollup merge of #162930 - clarfonthey:strlen-is-bounded, r=joshtriplett
Use niche length type for strlen to guarantee `isize::MAX` bound

Alternative to rust-lang/rust#162912.

r? hanna-kruppe
cc @Darksonn
2026-09-18 23:05:32 +02:00
Jonathan Brouwer
73cf3019a8 Rollup merge of #160401 - folkertdev:sparc-abi-fixes, r=beetrees
sparc: make ABI consistent with clang

fixes https://github.com/rust-lang/rust/issues/43894

I've hacked together a version of abi-cafe that can cross-compile. It finds many GCC vs. Clang inconsistencies, but for this target it found 3 ABI bugs that are specific to the rust implementation.

For reference

- [`SparcV8ABIInfo::{classifyArgumentType, classifyReturnType}`](6849789a8f/clang/lib/CodeGen/Targets/Sparc.cpp (L34-L59))
- [`DefaultABIInfo::{classifyArgumentType, classifyReturnType}`](6849789a8f/clang/lib/CodeGen/ABIInfoImpl.cpp (L17-L68))

## Pass ZST arguments

https://godbolt.org/z/P7KoqTWvr

The `sparc` ABI does not skip zero-sized arguments.

## Pass and return `f128` (i.e. `long double`) indirectly

The `long double` type, which corresponds to rust `f128`, is special-cased, it uses `getNaturalAlignIndirect` for both arguments and returns.

## pass aggregate arguments by reference

https://godbolt.org/z/hM8Gh1bfY

The implementation defers to `DefaultABIInfo::{classifyReturnType, classifyArgumentType}`, which use `byval` and `sret` for aggregate types.
2026-09-18 23:05:17 +02:00
beetrees
c60430f10f Add missing #[repr(C)] in UI, codegen and assembly tests 2026-09-18 14:36:44 +01:00
bors
498b89dd40 Auto merge of #161583 - RalfJung:x86-sse-abi, r=nikic
x86: on targets that requires SSE, use those registers for ABI



Now that https://github.com/llvm/llvm-project/issues/142321 is fixed, we can use the vector ABI without re-introducing https://github.com/rust-lang/rust/issues/139029. So this effectively reverts https://github.com/rust-lang/rust/pull/141309.

Since this means we are relying on the SSE target feature for the Rust ABI, we also need to turn the ABI target feature check into a hard error. If we don't do that, we'll get post-mono errors in some situations and plain miscompilations in others.

Also this will cause performance regressions on LLVM 22 and 21 as those don't have the fix for  https://github.com/llvm/llvm-project/issues/142321. IMO that's fine. Programs will do the right thing, they will just be a bit slower due to https://github.com/rust-lang/rust/issues/139029.

r? @nikic 
Cc @tgross35
2026-09-18 04:48:34 +00:00
ltdk
2605c8d41f Use niche length type for strlen to guarantee isize::MAX bound 2026-09-17 17:53:40 -04:00
James Barford-Evans
677806f9ae Remove applying inline attributes at the callsite 2026-09-17 21:01:31 +01:00
Jonathan Brouwer
85779afa09 Rollup merge of #161987 - folkertdev:single-fp-element, r=beetrees
fix `is_single_fp_element` for `s390x` and `x86`

In https://github.com/rust-lang/rust/pull/161950#discussion_r3886952310 we discovered that the old `is_single_fp_element` is incorrect in a number of ways.

- it did not consider `f16` or `f128`
- it did not consider transparent wrappers
- on x86, it incorrectly accepted over-aligned types
- on s390x, it incorrectly accepted single-element unions and arrays

So, in practice each target does something slightly different here, and I've split the function into two.

cc @beetrees
2026-09-17 21:00:08 +02:00
Ralf Jung
429c1c18ca x86: on targets that requires SSE, use those registers for ABI 2026-09-17 08:03:01 +02:00
Stuart Cook
f6b5137514 Rollup merge of #162826 - folkertdev:wasm-int-enum-abi, r=alexcrichton
wasm: fix ABI for enums with integer layout and ZST fields

fixes https://github.com/rust-lang/rust/issues/121408
follow-up to https://github.com/rust-lang/rust/pull/162806

Clang is doing something that is rather annoying for us to emulate: like with unions it looks at the structure of the type, not the representation. But in rust an `enum` that is represented as an integer is not considered an `aggregate` at all, yet may still need to be passed as one if it has any (even ZST) fields.

r? alexcrichton
cc @hanna-kruppe
2026-09-16 23:41:58 +10:00
Stuart Cook
a705949b7f Rollup merge of #156216 - Randl:const-for-impl, r=clarfonthey
implement const Iterator for Range

This allows the use of `for i in i..n` in `const`.

This I believe is interesting enough to be justified under https://github.com/rust-lang/rust/issues/155816

r? @oli-obk
2026-09-16 23:41:53 +10:00
Folkert de Vries
8aff3e62f2 wasm: fix ABI of repr(int) enums with ZST fields 2026-09-15 23:10:34 +02:00
Jonathan Brouwer
af5ab5897b Rollup merge of #162806 - folkertdev:wasm-union-abi, r=alexcrichton
wasm: correctly implement `union` trivial aggregates

A union with two scalar fields, even if they overlap exactly, is not a trivial aggregate, based on the implementation in `clang`:

e78970f80f/clang/lib/CodeGen/ABIInfoImpl.cpp (L338-L402)

It never explicitly considers unions, but essentially views them as records. The `clang` implementation is a plausible interpretation of the specification (though I'd like it to be a bit clearer):

83e5d715d0/BasicCABI.md (function-arguments-and-return-values)

> [2] Any struct or union that recursively (including through nested structs, unions, and arrays) contains just a single scalar value and is not specified to have greater than natural alignment.

We previously got this wrong. I also don't think this was really tested very well, so I added a bunch of test for various cases.

This change moves away from using the `homogeneous_aggregate` method, which is convenient because it is a bit broken and now we don't have to consider wasm when we fix that.

I've validated this against `clang` with abi-cafe.

r? alexcrichton
2026-09-15 16:46:25 +02:00
Folkert de Vries
417882b7cb wasm: correctly implement union trivial aggregates
A union with two scalar fields, even if they overlap exactly, is not a trivial aggregate
2026-09-15 13:24:43 +02:00
Evgenii Zheltonozhskii
81792041e9 Fix tests 2026-09-14 10:41:39 +03:00
Folkert de Vries
ee524a2ab7 fix is_single_fp_element for s390x and x86 2026-09-14 01:17:42 +02:00
Folkert de Vries
a44d3adcff sparc: pass and return f128 indirectly and return aggregates indirectly
long double (i.e. f128) is special-case in the sparc abi
2026-09-13 21:45:02 +02:00
Ben Kimock
81e7f004bd Add all the codegen test cases 2026-09-12 12:28:41 -04:00
Ben Kimock
a3038b6b2d Improve into_slice_range inlining 2026-09-12 12:28:33 -04:00
Hans Wennborg
2e331b1637 Update codegen-llvm/inline-debuginfo.rs for distinct DILocation 2026-09-08 08:59:13 +02:00
Jacob Pratt
4e27adb224 Rollup merge of #161697 - folkertdev:complex-sparc64-powerpc64, r=JohnTitor
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
2026-09-07 04:06:30 -04:00
bors
f207aa3913 Auto merge of #162333 - Zalathar:rollup-DdpfsFl, r=Zalathar
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#162324 (miri subtree update)
 - rust-lang/rust#162170 (bootstrap: use target's LLVM libdir when cross-compiling)
 - rust-lang/rust#158312 (Adds support for AArch64 SVE to inline assembly)
 - rust-lang/rust#159792 (A more readable debug map for IndexMaps)
 - rust-lang/rust#160745 (make closures act like MaybeDangling)
 - rust-lang/rust#161263 (break rustc_expand-rustc_middle dependency)
 - rust-lang/rust#161895 (std::sys::pal::sgx: fix mismatched alloc/free alignment)
 - rust-lang/rust#161940 (Promote `wasm32-wasip3` to a tier 2 target)
 - rust-lang/rust#161397 (coverage: Tidy tests and add some new ones)
 - rust-lang/rust#161616 (Report precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval)
 - rust-lang/rust#162248 (Add regression test for unsized const parameter default ICE)
 - rust-lang/rust#162250 (Fix hashing of span end columns in incremental compilation)
 - rust-lang/rust#162265 (cargotest: add lockfiles)
 - rust-lang/rust#162318 (bootstrap: Fix broken path for `./x doc compiler/rustc --open`)
2026-09-05 17:04:57 +00:00
Folkert de Vries
9e53b26932 make PowerPC64 Complex ABI GCC-compatible 2026-09-04 16:50:41 +02:00
Folkert de Vries
821527b611 make SPARC64 Complex ABI GCC-compatible 2026-09-04 16:50:41 +02:00
Folkert de Vries
cccde2f30b add placeholder for amdgpu 2026-09-04 16:50:40 +02:00
Ralf Jung
e7c3734a6a make closure-like types act like MaybeDangling 2026-09-04 16:35:10 +02:00
Folkert de Vries
a305a9c3b6 fix is_homogeneous_aggregate: use unit size, not total size 2026-09-04 16:15:13 +02:00
Jonathan Brouwer
f0fd2caeeb Rollup merge of #157808 - 1c3t3a:sanitizer-ignorelist, r=rcvalle
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
2026-09-04 09:44:44 +02:00
Jonathan Brouwer
86be46f85d Rollup merge of #162230 - zmodem:unchecked_math, r=nikic
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.
2026-09-03 20:03:00 +02:00
Bastian Kersting
c0e55d66cc 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.
2026-09-03 15:53:04 +00:00
Hans Wennborg
c5c326ba70 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.
2026-09-03 13:08:13 +02:00
Jonathan Brouwer
656ff175cf Rollup merge of #162151 - folkertdev:ppc-itanium, r=tgross35
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
2026-09-03 12:43:00 +02:00
Jonathan Brouwer
e48a722293 Rollup merge of #160564 - RalfJung:volatile-with-trap, r=nikic
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
2026-09-03 12:42:57 +02:00
Ralf Jung
ece2980246 volatile: allow accesses to trap 2026-09-02 14:46:04 +02:00
Folkert de Vries
bb0bcf25cc add itanium mangling test for f16 and f128 2026-09-01 21:50:00 +02:00
Folkert de Vries
45b97ea0cc itanium mangling: use minicore 2026-09-01 21:50:00 +02:00
Jonathan Brouwer
4679857002 Rollup merge of #161209 - scottmcm:redo-npot, r=clarfonthey
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.
2026-09-01 21:26:16 +02:00
Folkert de Vries
9ed2e0c0ca reformat itanium mangling test to be more readable 2026-09-01 20:44:08 +02:00
Jonathan Brouwer
08a94d8b20 Rollup merge of #162040 - weihanglo:bump-stage0, r=cuviper
bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463

This also contains a formatting change due to rustfmt bump.
Need this in order to test <https://github.com/rust-lang/rust/pull/161049>.
See also [#t-cargo > ✔ 1.99 beta backport](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/.E2.9C.94.201.2E99.20beta.20backport/with/619824670)

r? cuviper
2026-09-01 13:27:40 +02:00
Scott McMurray
f771946e61 Rework next_power_of_two to always be 1 << … 2026-08-31 12:42:39 -07:00
Weihang Lo
2060175f5a bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463
Also contains a formatting change due to rustfmt bump
2026-08-30 22:57:52 -04:00