Commit Graph

3831 Commits

Author SHA1 Message Date
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01: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
Jonathan Brouwer
a7be2941de Rollup merge of #163083 - nnethercote:rm-Diag-G, r=oli-obk
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in https://github.com/rust-lang/rust/pull/162630#discussion_r3988468478
2026-09-21 15:19:21 +02:00
James Barford-Evans
fe048b622e Only AArch64 has_reliable_f16b presently due to an LLVM codegen issue, also updated test 2026-09-21 09:32:49 +01:00
Jonathan Brouwer
0e00d84056 Rollup merge of #163062 - malezjaa:remove-aarch64-x30-asm-workaround, r=folkertdev
Use x30 register name with LLVM 23+

Closes rust-lang/rust#148900

Thanks to https://github.com/llvm/llvm-project/pull/167783, LLVM now recognizes the `x30`/`x29` register names.

r? @folkertdev
2026-09-21 10:16:10 +02:00
James Barford-Evans
c56a9917d8 Wire up f16b in backends 2026-09-21 08:57:52 +01:00
James Barford-Evans
cdde2f00b5 Add F16B to Float enum & wireup trivial matches 2026-09-21 08:57:51 +01:00
Nicholas Nethercote
30b8dfc353 Remove G generic param from Diag<'_, G>
It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.

This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.

Benefits:
- Many fewer generic parameters, including many functions where the
  genericity is entirely uninteresting. This includes every
  `Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
  need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.

The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
  This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
  This affects a lot of call sites. (It arguably makes call sites more
  self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
  previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
  any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
2026-09-21 09:57:42 +10:00
Jonathan Brouwer
0628b687f4 Rollup merge of #163021 - folkertdev:va-arg-ty-and-layout, r=adwinwhite
`va_arg`: pass in `TyAndLayout`

Just a refactor, no functional changes. It is weird I did not spot this before, it cleans up the code a bunch.
2026-09-20 17:04:30 +02:00
Jonathan Brouwer
29a8b638ca Rollup merge of #163066 - folkertdev:f128-not-aix, r=beetrees
don't mark `f128` as reliable on AIX

In fact the type is really not supported at all there.

In https://github.com/rust-lang/rust/pull/162979 we made `f128` reliable on powerpc64 when the `vsx` feature is enabled. Apparently this is the case on AIX, but it just does not implement `f128` at all.

r? tgross35
2026-09-20 17:04:27 +02: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
Folkert de Vries
506fbb7fd9 don't mark f128 as reliable on AIX
In fact the type is really not supported at all there.
2026-09-20 12:57:28 +02:00
Folkert de Vries
d61037d90f va_arg: pass in TyAndLayout
weird I did not spot this before, it cleans up the code a bunch
2026-09-20 12:52:41 +02:00
Jonathan Brouwer
a21a490e6f Rollup merge of #163003 - Zalathar:llvm-backend, r=Walnut356
cg_llvm: Move all code out of the crate root

Having non-trivial code in the crate root causes a few problems, most of which stem from every item being effectively `pub(crate)`:

- Fields/methods can't be private, so enforcing abstractions is impossible
- Every `use` becomes a de-facto re-export, leading to messy imports
- Moving items out of the root requires visibility adjustment

This PR therefore moves all non-trivial code out of the crate root, and into `rustc_codegen_llvm:🔙:llvm_backend`.

---

Deciding where to move the code *to* was a bit tricky. But the code being moved delegates a lot of its methods to other submodules in `back`, so creating another submodule in `back` seemed reasonable. I certainly like it more than the status-quo.

The main commit doesn't modify any of the code being moved, other than updating imports, as verified manually by:

```shell
git diff --color-moved --color-moved-ws=allow-indentation-change head^ head
```

There should be no change to compiler behaviour.
2026-09-19 16:08:51 +02:00
WANG Rui
ca8ee2fc33 Set target-abi module flag for LoongArch targets 2026-09-19 16:50:13 +08:00
Jonathan Brouwer
e69c8f3380 Rollup merge of #162979 - folkertdev:ppc-enable-f128, r=beetrees
mark `f128` as reliable on `powerpc64` with `+vsx`

This feature is only enabled by default for powerpc64le, and not enabled on the big-endian targets. Even with vsx, the default long double is ppcf128 on the big-endian targets, so LLVM calls the incorrect libcall. Also some libcalls just don't exist.

I tested this with and without `rustflags = ["-C", "target-feature=+vsx"]` in the `bootstrap.toml`:

```
./x.py test library/core --target powerpc64-unknown-linux-gnu
./x.py test library/core --target powerpc64le-unknown-linux-gnu
```

These all hit one failure, in the docs test for `library/core/src/keyword_docs.rs` where `become` is used: powerpc does not support guaranteed tail calls. Anyway, that is not relevant for f128 support.

Sadly `powerpc-unknown-linux-gnu` with `+vsx` hits the issue fixed in https://github.com/llvm/llvm-project/pull/216613, I've requested a backport for the fix.

r? beetrees or @tgross35
cc @Gelbpunkt
2026-09-19 08:45:38 +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
add93638af Rollup merge of #161777 - beetrees:f128-debuginfo, r=JohnTitor
Add Natvis visualiser and debuginfo tests for `f128`

To render f128s in debuggers on MSVC targets, this PR changes the compiler to output `f128`s as `struct f128 { low_bits: u64, high_bits: u64 }`, and includes a Natvis visualiser that displays the float in hexdecimal format (similar to the `LowerHex` impl in rust-lang/rust#160626), as unlike `f16` there's no larger supported float format to convert to and trying to write a float to decimal string converter in Natvis didn't seem practical. gdb, lldb and cdb tests are also included for `f128`, although gdb does not yet correctly identify the float format.

I did consider also displaying a `double` approximation of the `f128` (as the debugger will convert that to a decimal string) but decided against it as `f64` has a significantly smaller exponent range too (meaning very large or small `f128`s couldn't have an approximation anyway) and `cdb` and `WinDbg` both seem to round all floating-point numbers to 6 decimal places, meaning the displayed number is (double) rounded even further than `f64` precision and is useless for tiny values.

Closes rust-lang/rust#121837
Tracking issue: rust-lang/rust#116909
2026-09-19 08:45:30 +02:00
Jonathan Brouwer
ddab8825b7 Rollup merge of #161424 - folkertdev:va-arg-f128, r=tgross35
implement `VaArgSafe` for `f128`

On some platforms, especially when `long double` is IEEE f128 on the platform.
2026-09-19 08:45:30 +02:00
Zalathar
eb921eeb3c Move all code out of the crate root
Having non-trivial code in the crate root causes a few problems, most
of which stem from every item being effectively `pub(crate)`:

- Fields/methods can't be private, so enforcing abstractions is impossible
- Every `use` becomes a de-facto re-export, leading to messy imports
- Moving items out of the root requires visibility adjustment
2026-09-19 12:23:37 +10:00
Zalathar
904fd444c2 Increase visibility of some crate-root items before moving them
This makes it easier to confirm that the move itself doesn't modify any code.
2026-09-19 12:23:36 +10:00
Folkert de Vries
a3ad87e548 mark f128 as reliable on powerpc with +vsx
This feature is only enabled by default for powerpc64le, and not enabled on the big-endian targets. Even with vsx, the default long double is ppcf128 on the big-endian targets, so LLVM calls the incorrect libcall. Also some libcalls just don't exist
2026-09-18 21:47:37 +02:00
Folkert de Vries
3d281d4881 implement VaArgSafe for f128 2026-09-18 20:28:54 +02:00
beetrees
b7bad07da0 Add Natvis visualiser and debuginfo tests for f128 2026-09-18 19:04:42 +01:00
Augie Fackler
96b774bdd6 PassWrapper: adapt to LLVM reading exception model from module flag 2026-09-18 08:52:10 -04:00
James Barford-Evans
677806f9ae Remove applying inline attributes at the callsite 2026-09-17 21:01:31 +01:00
Jonathan Brouwer
c79bc2c916 Rollup merge of #162817 - durin42:llvm-24-thread-model, r=nikic
rustc_{codegen_,}llvm: adapt to new ThreadModel API

LLVM 24 [has moved](e733cebdf7) from TargetOptions::ThreadModel to specifying thread-model as a module flag. This catches us up.

@rustbot label: +llvm-main
2026-09-17 21:00:13 +02: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
Jonathan Brouwer
ce606c6186 Rollup merge of #160544 - zachs18:stabilize-trim_prefix_suffix, r=clarfonthey
Stabilize `feature(trim_prefix_suffix)` (`{str, [T], Path}::trim_prefix` and `{str, [T]}::trim_suffix`)

Closes rust-lang/rust#142312 (tracking issue)

FCP completed [here](https://github.com/rust-lang/rust/issues/142312#issuecomment-4920020056). There was discussion during FCP about a possibly adding `strip_circumfix`, but that wasn't mentioned as blocking.

r? libs-api
2026-09-17 16:50:48 +02:00
Nicholas Nethercote
8515e12560 Remove global_backend_features query
It's now possible to get the backend features (a `Vec<String>`) when the
codegen backend is started, pass it back through `CodegenBackendInit`,
and just store it in the `Session`. This removes the need for the query.

Also:

- `WriteBackendMethods::target_machine_factory` no longer needs the
  `target_features` parameter, because it's now available through the
  `sess` parameter.

- `CodegenContext` no longer needs the `backend_features` field because
  we can use `sess.global_backend_features` instead.

- `CodegenBackend::provide` is now a no-op for all the in-tree backends.
  I haven't removed it because out-of-tree backends still rely on it.
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
81210c9d79 Change CodegenBackend::init to take &mut self
It currently takes `&self`, which is a bit strange for an `init` method.
As a result, the Cranelift and GCC backends have to use types with
interior mutability.

This commit changes it to `&mut self`. Benefits:

- The Cranelift backend can use `Option` instead of `OnceCell` to
  indicate uninit vs. init.

- The GCC backend can avoid `Mutex`, and use `bool` instead of
  `AtomicBool`, which makes things much simpler. The commit also
  restructures `GccCodegenBackend` to mirror `CraneliftCodegenBackend`:
  just contain an `Option<BackendConfig>`, which makes the uninit vs.
  init distinction foolproof. (E.g. no need to set `lto_supported` to
  false and then later overwrite it with the real value.) As part of
  this the `LockedTargetInfo` type is renamed `SharedTargetInfo` because
  that better matches its new internals. (All this compiles both with
  and without the "master" feature set.)
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
51673f89e1 Split build_session
Session creation is currently awkward: we build a mostly-initialized
session, then use it to initialize a codegen backend, and then use the
codegen backend to finish initializing the session.

And it's not just awkward: within the Cranelift backend's `init` method
`sess.lto()` is called, which consults `sess.thin_lto_supported`,
*before* that field has been properly set! In practice it had no effect
but it's worth fixing.

This commit cleans up this mess. It introduces `EarlySession`, which
contains just four `Session` fields, the ones that are needed for
codegen backend initialization. It is now a field within `Session`, and
`Session` derefs to `EarlySession` to avoid changing a zillion
`sess.target`/`sess.opts`/etc. occurrences. `EarlySession` is passed to
`init`, which returns a `CodegenBackendInit` that contains the
backend-specific information needed to build a `Session`. (It replaces
the `replaced_intrinsics`, `fallback_intrinsics`, and
`thin_lto_supported` methods.) The `Session` can then be built in a
single step. No more `Session`/`CodegenBackend` initialization
intermingling.

A few functions that previously took a `Session` now take something
else, e.g. a `Target`. Some `Session` methods are now `EarlySession`
methods. And a new `early_lto` method is used for Cranelift's LTO check.
2026-09-16 15:29:42 +10:00
Zachary S
9559b382e8 Stabilize trim_prefix_suffix 2026-09-15 15:23:26 -05:00
Augie Fackler
5dd4631041 rustc_{codegen_,}llvm: adapt to new ThreadModel API
LLVM 24 has moved from TargetOptions::ThreadModel to specifying
thread-model as a module flag. This catches us up.
2026-09-15 12:21:54 -04:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Jonathan Brouwer
305d36bc80 Rollup merge of #162630 - nnethercote:simplify-Diag-G, r=oli-obk
Simplify the `G` in `Diag<'a, G>`

The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.

r? @oli-obk
2026-09-14 15:16:02 +02:00
Jonathan Brouwer
09c7c12af1 Rollup merge of #161903 - nnethercote:fix-target_config-cycle, r=nikic
Fix initialization cycle in `target_config`

There is an initialization cycle in `target_config`. Details in the final commit. The previous commits are precursors that support the changes in the final commit.

r? @nikic
cc @cuviper @RalfJung @Zalathar @Patryk27
2026-09-14 15:15:56 +02:00
Folkert de Vries
ee524a2ab7 fix is_single_fp_element for s390x and x86 2026-09-14 01:17:42 +02:00
Jonathan Brouwer
348c0ba6b1 Rollup merge of #162710 - Zalathar:version-safe, r=chenyukang
cg_llvm: Make the LLVM version-check bindings safe

- Follow-up to https://github.com/rust-lang/rust/pull/161788
---

These version-check functions should always be safe to call, so marking them `safe` avoids some unsafe blocks at call sites.

There should be no change to compiler behaviour.
2026-09-13 16:29:13 +02:00
Zalathar
75d7c935f6 Make the LLVM version-check bindings safe 2026-09-13 13:54:06 +10:00
bors
6474e99989 Auto merge of #162598 - Walnut356:msvc_scopes, r=jieyouxu
Fix the remaining `tests/debuginfo` failures on `msvc` 



Fixes the remainder of the failing tests from https://github.com/rust-lang/rust/issues/161657

I used lldb 22.1 to individually check each of the `S_DEFRANGE_REGISTER_REL_INDIR` node (using e.g. `llvm-pdbutil dump --symbols ".\build\x86_64-pc-windows-gnu\test\debuginfo\<test_name>.lldb\a.pdb" | rg "unknown \(4471\)"`)

Any tests with an `unknown (4471)` node (4471/0x1177 being the enum value for `S_DEFRANGE_REGISTER_REL_INDIR`) got an `[msvc]` revision to disable on LLDB older than 23.1.0.

I then updated to LLDB 23.1.0 and disabled any remaining test failures that ocurred due to the variable shadowing behavior (so that they do not instantly break when we eventually run 23 in CI). Technically we could have avoided disabling those tests by using the python API to inspect individual slots of the frame, or by printing the whole frame at each step and matching against that, but the amount of effort seems not worth it until [we determine whether or not LLDB can/will improve its behavior here.](https://github.com/llvm/llvm-project/issues/221696).

One note, LLDB 23 seems to like it even less when we use the parent debugger instance for the test harness. I'll fix that in a followup PR since it requires a little bit of fiddling to get it to work with LLDB <23 (the short version is it's much harder to exit with a non-0 status code when using a nested debugger instance. We should be able to run something like `os.kill(os.getpid(), signal.SIGTERM)` from the internal python to kill the parent LLDB process to work around that)

There were a few fixes that required special handling

### `borrowed-basic.rs`, `basic-types-globals.rs`, `reference-debuginfo.rs` 

LLDB appears to have changed their default formatting for chars again in v23.1.0 (`U+0x00000061 U'a'` -> `U+0061 U'a'`) luckily these are similar enough that we can use a wildcard to pass in both cases


### `dummy-span.rs`

There was a conditional to prevent using the (0,0) default dummy span on MSVC with a comment explaining why (it would default to the first line of the file instead). I removed the `is_msvc` check and this test worked and didn't break anything else so, best guess this got fixed at some point and the comment was outdated?

In any case, with this PR, the entirety of `tests/debuginfo` passes on `linux-gnu`, `windows-gnu`, and `windows-msvc` 🎉🎉

<img width="847" height="444" alt="image" src="https://github.com/user-attachments/assets/4c0f14d1-5ad4-4234-8380-59ad18ad6309" />


<img width="817" height="208" alt="image" src="https://github.com/user-attachments/assets/87819fcd-cdbb-4fd4-b2f8-c6cf2ecf5db3" />


r? @Kobzol, @jieyouxu
2026-09-13 03:03:32 +00:00
Nicholas Nethercote
09bf6de39e Remove EmissionGuarantee
It's a trait that is used to give `Diag::emit` different return types
depending on the `G` in `Diag<'_, G>`. It works, but it's overkill.
There are only four different `G` types in practice (`BugAbort`,
`FatalAbort`, `ErrorGuaranteed`, and `()`) and having inherent `emit`
methods for each of those four concrete `Diag<'_, G>` types is good
enough.

This commit makes that change. This removes `EmissionGuarantee`
trait bounds from many places, which is nice.
2026-09-12 11:21:03 +10:00
Jonathan Brouwer
7cd747decf Rollup merge of #160023 - antoyo:ssa-indirect-return, r=workingjubilee
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2

This continues the work that @FractalFir done in rust-lang/rust#144976.

**I managed to make this work, so this confirms the original approach works and is ready to merge.**

r? workingjubilee

(assigning the same reviewer as the original PR)

# The problem

The current way `cg_ssa` handles `PassMode::Indirect` is fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.

In order to function correctly, `cg_gcc` requires the `sret`(indirect return) pointer to be treated in a special way.

# The solution

This PR separates the `sret` pointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.

The PR is based on this [zulip suggestion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Bootstrap.20of.20rustc.20with.20rustc_codegen_gcc/near/526487725).

# Assumptions I made.

The PR makes certain assumptions about the ABI handling.

1. No LLVM intrinsic returns via sret. [According to my sources](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20LLVM.20intrinsics.20return.20via.20PassMode.3A.3AIndirect.3F), this is always true.
2. Tail calls don't currently return via `sret`. From [asking about](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20tail.20calls.20return.20indirectly.28via.20a.20pointer.29.3F/near/532984507), it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.
3. TLS shims don't perform indirect returns, and asserts and drops also don't perform indirect returns(since they return nothing) - those assumptions seemed reasonable.
4. Inline assembly calls don't use indirect returns. I *assumed* functions like `inline_asm_call` will not need the `sret` handling code. I am not 100% sure about this, tough.
2026-09-11 12:45:02 +02:00
Walnut
52a6da2f6a output regular dummy spans on msvc 2026-09-10 09:21:19 -05:00
bjorn3
052ee70292 Don't rely on codegen emitting fn_abi_of_* errors in abi checks
This avoids a delayed bug if compilation is aborted between checking
function ABIs and codegening all functions.
2026-09-10 09:40:28 +02:00
Antoni Boucher
7d0d2731ee Add missing direct return arguments 2026-09-09 12:00:22 -04:00
Antoni Boucher
d244854ed7 Address review 2026-09-09 11:29:12 -04:00