Commit Graph

4235 Commits

Author SHA1 Message Date
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
Jacob Pratt
d971af8b59 Rollup merge of #162514 - nnethercote:simplify-diag-Levels, r=oli-obk
Simplify diagnostic levels

This PR separates diagnostic levels from subdiagnostic levels and does a few preliminary cleanups. Details in individual commits.

r? @oli-obk
2026-09-11 00:03:10 -04:00
Nicholas Nethercote
6331ab69b4 Introduce Sublevel for errors
Currently `Level` is used for both diagnostics and subdiagnostics. But
both diagnostics and subdiagnostics only use some of the levels. This
commit introduces `Sublevel` to tighten up the representation and
prevent impossible combinations.
2026-09-11 06:46:46 +10:00
Jonathan Brouwer
3532a4cefb Rollup merge of #162542 - xingxue-ibm:gate-elf-code-for-elf, r=khyperia
Gate ELF code in metadata.rs for ELF only

This PR gates ELF specific code for `BinaryFormat::Elf`. With this change, fallback for PowerPC64 on AIX is no longer needed.

---------

Assisted-by: IBM Bob
The issue was discovered by IBM Bob while checking changes for other things, and I personally verified the bug. Although the fix is trivial, I ran it through IBM Bob to make sure I wasn’t missing anything.
2026-09-10 22:34:00 +02:00
Antoni Boucher
a714a9e8df Improve the new indirect return API 2026-09-09 11:29:11 -04:00
Fractal Fir(Michał Kostrubiec)
74bba56ab9 Apply suggestions from code review
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2026-09-09 11:14:31 -04:00
FractalFir
e6b7dc8152 Ported cg_gcc to the new cg_ssa version 2026-09-09 11:14:31 -04:00
FractalFir
cca9f306f0 Refactored the handling of the indirect return pointer in cg_ssa to allow for more correct ABI handling in cg_gcc 2026-09-09 11:14:31 -04:00
Xing Xue
1e18d10e2b Gate ELF code in metadata.rs for ELF only. 2026-09-09 11:01:27 -04:00
Jonathan Brouwer
82ffd1cc73 Rollup merge of #162453 - nnethercote:min-DiagCtxt-methods, r=oli-obk
Minimize `DiagCtxt` methods

We have `DiagCtxt`, `DiagCtxtInner`, and `DiagCtxtHandle`. They're all necessary, but the method placement is inconsistent. This commit establishes a clearer rule: methods should *not* go on `DiagCtxt` whenever possible.

Benefits:

- Simpler rule for deciding where to put a method.

- `impl Deref for DiagCtxtHandle` can be removed, including its non-standard double-reference `&&'a DiagCtxt` return value. This makes it impossible to accidentally discard a taint target by calling `handle` on a `DiagCtxtHandle`.

- Catches some places where we were calling `dcx.handle()` when `dcx` was already a handle.

r? @oli-obk
2026-09-09 15:01:30 +02:00
Jonathan Brouwer
16f306cb78 Rollup merge of #162309 - sgasho:offload-clang-linker-wrapper, r=ZuseZ4
offload: automate manual clang-linker-wrapper step

automate manual clang-linker-wrapper step from https://rustc-dev-guide.rust-lang.org/offload/usage.html
extract bitcode from device.bin and then wraps it into the host module.
needs some refactoring.

r? @ZuseZ4
2026-09-08 18:19:36 +02:00
Nicholas Nethercote
d571cae83e Minimize DiagCtxt methods
We have `DiagCtxt`, `DiagCtxtInner`, and `DiagCtxtHandle`. They're all
necessary, but the method placement is inconsistent. This commit
establishes a clearer rule: methods should *not* go on `DiagCtxt`
whenever possible.

Benefits:

- Simpler rule for deciding where to put a method.

- `impl Deref for DiagCtxtHandle` can be removed, including its
  non-standard double-reference `&&'a DiagCtxt` return value.
  This makes it impossible to accidentally discard a taint target by
  calling `handle` on a `DiagCtxtHandle`.

- Catches some places where we were calling `dcx.handle()` when `dcx`
  was already a handle.
2026-09-08 15:25:09 +10:00
Jonathan Brouwer
f04af2086f Rollup merge of #160197 - susitsm:restrict-inline-asm-cookies, r=petrochenkov
Restrict LLVM inline asm location cookie usage. Fixes #150451

The parallel frontend makes the cookies nondeterministic in their current form, resulting in nondeterministic outputs when bitcode is emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds. See rust-lang/rust#150451 for details.

Fixes rust-lang/rust#150451

r? bjorn3
2026-09-07 17:08:07 +02:00
sgasho
f9017b1630 add rpath 2026-09-06 14:35:53 +00:00
Stuart Cook
eaa6c852f5 Rollup merge of #161940 - alexcrichton:wasip3, r=davidtwco
Promote `wasm32-wasip3` to a tier 2 target

This commit updates documentation, configuration, etc, within the compiler to promote the `wasm32-wasip3` target to tier 2. This means that precompiled binaries will be made available in `rustup` for usage. This target MCP for this change is [rust-lang/compiler-team/100][mcp].

This target requires LLVM 23 which rustc recently has updated to, and then additionally requires wasi-sdk-34 which additionally uses LLVM 23 which was also updated recently. With these ingredients in place the ABI for `wasm32-wasip3` is all lined up and ready to go. These changes were all necessary to bring cooperative threading to the target in the future, but that's not quite ready in the ecosystem yet.

I've locally been testing this target and it's done well so far, but I suspect this'll need subsequent bug fixes here and there as other new issues crop up. I don't expect anything major will be necessary, however.

[mcp]: https://github.com/rust-lang/compiler-team/issues/1001
2026-09-05 23:04:49 +10:00
Matyas Susits
970cb98f0e Disable inline asm line info cookies when llvm bitcode is saved or LTO is enabled
The parallel frontend makes the cookies nondeterministic in their
current form, resulting in nondeterministic outputs when bitcode is
emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds.
2026-09-05 11:52:40 +02:00
sgasho
c321d90e6f offload: automate manual clang-linker-wrapper step 2026-09-04 16:59:41 +00:00
Ralf Jung
e7c3734a6a make closure-like types act like MaybeDangling 2026-09-04 16:35:10 +02:00
Ralf Jung
2fa835fc72 make -Ctarget-feature warnings more explicitly FCWs 2026-09-04 08:22:14 +02:00
Alex Crichton
66d9e739ff Promote wasm32-wasip3 to a tier 2 target
This commit updates documentation, configuration, etc, within the
compiler to promote the `wasm32-wasip3` target to tier 2. This means
that precompiled binaries will be made available in `rustup` for usage.
This target MCP for this change is [rust-lang/compiler-team/100][mcp].

This target requires LLVM 23 which rustc recently has updated to, and
then additionally requires wasi-sdk-34 which additionally uses LLVM 23
which was also updated recently. With these ingredients in place the ABI
for `wasm32-wasip3` is all lined up and ready to go. These changes were
all necessary to bring cooperative threading to the target in the
future, but that's not quite ready in the ecosystem yet.

I've locally been testing this target and it's done well so far, but I
suspect this'll need subsequent bug fixes here and there as other new
issues crop up. I don't expect anything major will be necessary,
however.

[mcp]: https://github.com/rust-lang/compiler-team/issues/1001
2026-09-03 07:27:00 -07:00
Jonathan Brouwer
198bd21de8 Rollup merge of #161971 - hanna-kruppe:rm-flag-satfpcast, r=RalfJung
Remove -Zsaturating-float-casts flag

I added this flag back in 2017 (rust-lang/rust#45205) to enable benchmarking of the saturating semantics when it was newly implemented and still experimental. But saturation has been the official semantics for float<->int `as` casts for years now. A flag for turning it off no longer serves any purpose, it's just `-Zplease-miscompile-casts` now.
2026-09-01 21:26:14 +02:00
Jonathan Brouwer
bcaa514284 Rollup merge of #162097 - mejrs:instrumentfnattr, r=JonathanBrouwer
Deduplicate `InstrumentFnAttr`

cc @pmur

Instead of having a `Default` variant (which can't be specified in the attribute, it only does on/off), use an Option to model "no attribute used".
2026-09-01 13:27:46 +02:00
Jonathan Brouwer
dbfa398db0 Rollup merge of #162075 - mejrs:track_caller_closure_gating, r=JonathanBrouwer
Move track_caller on closures gating to attribute parsing

I noticed this while reviewing rust-lang/rust#161958
2026-09-01 13:27:45 +02:00
mejrs
8717cbaa84 Deduplicate InstrumentFnAttr 2026-08-31 20:48:05 +02:00
mejrs
e18a0126ea Move track_caller on closures gating to attribute parsing 2026-08-31 19:12:19 +02:00
Folkert de Vries
178eb4b50f attach naked function target features to module assembly 2026-08-31 00:25:34 +02:00
Hanna Kruppe
c7d949d9ea Remove -Zsaturating-float-casts flag
I added this flag back in 2017 to enable benchmarking of the saturating
semantics when it was newly implemented and still experimental. But
saturation has been the official semantics for float<->int `as` casts
for years now. A flag for turning it off no longer serves any purpose,
it's just `-Zplease-miscompile-casts` now.
2026-08-29 13:50:44 +02:00
Jonathan Brouwer
8e3d555214 Rollup merge of #159103 - aapoalas:reborrow/fix-borrowed-place, r=oli-obk
fix(reborrow): recursive implementation

If Reborrow finds '&'a mut T' fields where 'a is the Reborrowed type's first lifetime parameter (currently the only lifetime that is allowed to reborrow) then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into.

This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.

r? @oli-obk
2026-08-28 10:15:37 +02:00
Aapo Alasuutari
5686e56377 fix(reborrow): recursive implementation
* Implement Reborrow as a recursive operation

If Reborrow finds '&'a mut T' fields then it inserts
a Deref and borrow of the T, and likewise if it finds a
'T: Reborrow' field then the field type is recursed into.

This makes Reborrow always produce the correct borrow checking logic at
the cost of most probably being inconsiderately expensive. The thinking
is that performance will be a followup consideration.
* PhantomDeref
* Simpler deref test

* Add more PhantomDeref unreachability assertions
* Write out lifetime omission
* Document ProjectionElem::PhantomDeref
* Comment half of reborrow tests
* fix PhantomDeref conflicting with AccessDepth::Shallow
* Recheck CoerceShared in borrowck TypeChecker to ensure its lifetimes make sense
* Fix rebase
* Changes... but where to?
* Typo fix

* Improve comment
* Use fully_perform_op to evaluate CoerceShared trait in borrowck
* More CoerceShared comment
* Comment rest of Reborrow tests

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2026-08-27 20:03:59 +00:00
Jonathan Brouwer
f7f990ffbe Rollup merge of #161701 - mati865:dlltool-helper-rename, r=bjorn3
Rename dlltool helper function

It doesn't check for MinGW toolchain (`windows-gnu` or `windows-gnullvm`), but `windows-gnu` only. All the callsites use that helper to decide whether dlltool should be used.

r? @bjorn3
2026-08-26 17:23:21 +02:00
Ralf Jung
de2780a2a2 rename rust_target_features query to make it clear that these are *all* target features 2026-08-25 08:10:45 +02:00
Mateusz Mikuła
8f302fb281 Rename dlltool helper function 2026-08-24 23:33:09 +02:00
Jonathan Brouwer
3cc643bd77 Rollup merge of #160132 - folkertdev:pad-i32-count, r=bjorn3
make `pad_i32` of `PassMode::cast` an integer

so that we can specify more than one i32 of padding. This PR only adds the functionality but does not yet use it: there should be no functional changes.

This is needed for the ABI of `Complex<{ float }>` on 32-bit powerpc. Other mechanisms, e.g. using `PassMode::prefixed` don't appear to work.

More discussion is in [#t-compiler/help > power complex abi](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/power.20complex.20abi/with/613294420).
2026-08-24 15:06:55 +02:00
Stuart Cook
ddbc26dda8 Rollup merge of #161601 - GTimothy:empty-path-optim, r=fmease
Path: use optimized is_empty() method

A simple change: use the new `Path::is_empty` method, that directly checks if the inner `OsStr` is empty instead of allocating a new `Path` and doing `Path` equality.
2026-08-24 14:21:58 +10:00
GTimothy
3dee3c5ff9 Path: use optimized is_empty() method 2026-08-23 15:27:25 +02:00
Ralf Jung
33100e44a3 target_featurs: avx2 and probably all of sse is incompatible with soft-float ABI 2026-08-23 13:57:03 +02:00
Jonathan Brouwer
0ffd0ecd67 Rollup merge of #161465 - jdupak-ms:patch-1, r=wesleywiser
Remove leftover immediate creation

`from_immediate` calls left over from refactor d3d3485dd4 can create invalid LLVM IR
2026-08-22 10:48:40 +02:00
Folkert de Vries
d5d5ff7edf make pad_i32 of PassMode::cast an integer
so that we can specify more than one i32 of padding.
2026-08-21 21:25:26 +02:00
Jakub Dupak (Microsoft)
13bf3263e4 Remove leftover immediate creation
`from_immediate` calls left over from refactor d3d3485dd4 can create invalid LLVM IR
2026-08-21 15:56:04 +02:00
Jacob Pratt
cc58c4218f Rollup merge of #161259 - mejrs:attr_structures, r=JonathanBrouwer
move some attribute related structs out of rustc_attr_ir

This changes it so that

- rustc_session no longer depends on rustc_attr_ir
- rustc_attr_ir no longer depends on rustc_target (which is a fairly sizeable crate)
- rustc_attr_ir and rustc_target can compile in parallel

Previous graph:
<img width="985" height="512" alt="image" src="https://github.com/user-attachments/assets/cbde2414-043e-45f2-88a2-f77a5c9df60c" />

Graph with this PR:
<img width="1248" height="474" alt="image" src="https://github.com/user-attachments/assets/e0e13794-b17b-4337-8768-f0191cb1c0e6" />

r? @JonathanBrouwer
2026-08-21 08:43:39 -04:00
mejrs
8d970ffe69 Move NativeLibKind 2026-08-21 10:35:04 +02:00
mejrs
38af4a23c2 move CrateType 2026-08-21 10:35:02 +02:00
bors
16a623ad67 Auto merge of #161434 - jhpratt:rollup-hq3P7uc, r=jhpratt
Rollup of 25 pull requests

Successful merges:

 - rust-lang/rust#152617 (std: implement `sleep_until` for Fuchsia)
 - rust-lang/rust#158934 (diagnostics: fix `let x: vec![]` suggestion pointing into stdlib)
 - rust-lang/rust#160995 (Tiny readability cleanups for initialization dataflow analyses)
 - rust-lang/rust#161277 (bootstrap: Move all non-module items out of the crate root)
 - rust-lang/rust#161295 (std: don't panic on long-elapsed deadlines for `sleep_until`)
 - rust-lang/rust#161368 (Double-word align `_Unwind_Exception`)
 - rust-lang/rust#161370 (Uplift rustfmt macro formatting fix)
 - rust-lang/rust#161378 (`FlowSensitiveAnalysis` cleanups)
 - rust-lang/rust#161420 (Bump wasm-component-ld to 0.5.30)
 - rust-lang/rust#161429 (Tighten allocator `Send`/`Sync` requirements for `Arc` in preparation for refactor)
 - rust-lang/rust#158032 (Offload expose device selection)
 - rust-lang/rust#158855 (Add `desktop` method to `CommandExt`)
 - rust-lang/rust#160299 (Stabilize `bool::toggle`)
 - rust-lang/rust#160842 (Apply `&[T]` visualizer to `*const [T]`, `*mut [T]` and `Box<[T]>`)
 - rust-lang/rust#160981 (Partially support building and locating wasm proc-macros)
 - rust-lang/rust#161199 (Add regression test for non lifetime binders)
 - rust-lang/rust#161212 (rust-installer/install-template.sh: catch cp(1) error when installing…)
 - rust-lang/rust#161302 (Add regression test for inconsistent import resolution from issue 147208)
 - rust-lang/rust#161329 (Add regression tests for a few fixed issues with E-needs-test)
 - rust-lang/rust#161330 (Add regression test for nested RPIT not an iterator ICE)
 - rust-lang/rust#161331 (Bitset simplifications)
 - rust-lang/rust#161340 (rustdoc: enable scrolling only on table/code)
 - rust-lang/rust#161351 (Cleanup: Move impl of `#[rustc_dump_object_lifetime_defaults]`)
 - rust-lang/rust#161355 (Add file path to some archive build errors)
 - rust-lang/rust#161373 (Allow running EC2 jobs locally)
2026-08-21 06:25:29 +00:00
Jacob Pratt
8abcab5a5d Rollup merge of #161355 - bjorn3:archive_error_message, r=mu001999
Add file path to some archive build errors

This would have been useful to have while debugging a problem in cg_clif.
2026-08-20 21:34:38 -04:00
Jacob Pratt
c50742ed14 Rollup merge of #158032 - Sa4dUs:offload-device-selection, r=ZuseZ4
Offload expose device selection

get amount of available devices with `omp_get_num_devices` and add arg to the intrinsic for device selection

r? @ZuseZ4
2026-08-20 21:34:27 -04:00
mejrs
d128c4291b remove duplicate import 2026-08-20 23:11:38 +02:00
mejrs
7cd9c920cd rustc_session; remove rustc_lint_defs rex-exports 2026-08-20 23:02:49 +02:00
Josh Stone
d3303c0d45 update cfg(bootstrap) 2026-08-19 09:27:40 -07:00
bjorn3
eae69d81bc Add file path to some archive build errors
This would have been useful to have while debugging a problem in cg_clif.
2026-08-19 14:49:31 +02:00
Jonathan Brouwer
765bc489c8 Rollup merge of #160058 - RalfJung:atomic-volatile, r=JohnTitor
atomic volatile: add intrinsics

Extend the atomic load/store intrinsics to also support volatile atomic load/store.
Tracking issue: https://github.com/rust-lang/rust/issues/158947.
Library APIs that use these intrinsics will be added inn a future PR.

The GCC and cranelift implementations ignore the volatile flag, not sure how that should be implemented for them.
2026-08-17 20:58:24 +02:00