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.
Simplify diagnostic levels
This PR separates diagnostic levels from subdiagnostic levels and does a few preliminary cleanups. Details in individual commits.
r? @oli-obk
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.
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.
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
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
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.
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.
Fixesrust-lang/rust#150451
r? bjorn3
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
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.
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
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.
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".
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.
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
* 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>
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
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).
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.
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
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.