intrinsics: Rename `abort` to `abort_immediate`
The semantics of `intrinsics::abort()` are closer to what we have unstably as `abort_immediate()` than to `process::abort()` or `libc::abort()`. Rename it to make more clear that the intrinsic is more of an intentional crash with platform-specific behavior than what `libc::abort()` tries to be (i.e. raising `SIGABRT`).
If desired, a new intrinsic like `abort_gracefully` could be introduced that performs platform-specific behavior. This would more cleanly unblock https://github.com/rust-lang/rust/pull/149780.
See also discussion at the tracking issue for `immediate_abort` https://github.com/rust-lang/rust/issues/154601.
Update the minimum external LLVM to 22
With this change, we'll have stable support for LLVM 22 and 23.
For reference, the previous increase to LLVM 21 was rust-lang/rust#153684.
cc @rust-lang/wg-llvm @durin42
r? nikic
The semantics of `intrinsics::abort()` are closer to what we have
unstably as `abort_immediate()` than to `process::abort()` or
`libc::abort()`. Rename it to make more clear that the intrinsic is more
of an intentional crash with platform-specific behavior than what
`libc::abort()` tries to be (i.e. raising `SIGABRT`).
Emit llvm dereferenceable in more cases on newer LLVM versions
On llvm >= 23 emit `dereferenceable` even without `nofree`, since https://github.com/llvm/llvm-project/pull/204795 makes `dereferenceable` act "at a point" / not imply `nofree`.
Additionally restrict `dereferenceable` to `&Freeze` / `&mut Unpin` / `Box<Unpin, _>` only (this is only relevant for `llvm >= 23` as otherwise `!Freeze`/`!Unpin` suppress `nofree` and as such `dereferenceable`).
r? nikic
I thought this will be a bit harder change, but since your refactoring in rust-lang/rust#156281 it's actually trivial ^^'
Draft because I don't think this can be tested prior to LLVM update. I'm also not sure if the version check I did is the appropriate one...
cc @RalfJung
Refactor CodeGen Pipeline Setup into a Single Function
This patch refactors setup of the LegacyPassManager for CodeGen into a single function. This simplifies some things (lifetime for the LegacyPM object), but is primarily aimed at enabling rustc to use the new runCodeGenPipeline abstraction (introduced in LLVM 24) which handles all of these details within LLVM and additionally defaults to the NewPM when a target opts-in/the correct LLVM flag is passed.
A common definition is like a weak definition except that it must be a
zero-initialized static and when merging two common symbols with the
same name, the size and alignment are set to the higher of both symbols.
This is used for tentative definitions in C and doesn't have any reason
to exist outside of that. This behavior doesn't work across dylibs and
common symbols have inconsistent behavior across linkers [1]. It is also
fragile to rely on getting the largest size of all common symbol
definitions as a (possibly smaller) global definition can override it.
Link: https://maskray.me/blog/all-about-common-symbols [1]
Add support for -Zsanitizer-cfi-minimal-runtime
For production use, we should only link in the ubsan_minimal runtime,
instead of the complete ubsan runtime. This adds support for both
cfi-recover and cfi-diag to use the minimal runtime when
`-Zsanitizer-cfi-minimal-runtime` is specified.
This also includes tests, to ensure the flag can only be used if either
cfi-recover or cfi-diag is enabled, it doesn't disrupt the original
behavior, and links in the correct runtime when specified.
cc @1c3t3a
?r rcvalle
Less `SpanData` in diagnostics
`SpanData` should really just be an internal detail of `Span`, and its use is worth minimizing. This PR gets rid of two uses.
Details in individual commits.
r? @bjorn3
Support -Z merge-functions with gcc and add stack-protector asm tests
This is a part of the stack-protector work.
Adding support for merge-functions is not strictly needed, but it does prevent breakage if the GCC function merging logic changes.
Not adding tests for -Z merge-functions since I don't see any such tests for the LLVM side of it.
No lines in this PR were written by LLM, though I did use it for help in reviewing and reading documentation.
Because they're all just special cases of warnings. This requires
introducing a new `Option<EmissionOverride>` field to `Warning` that
describes the special case behaviour; the `DiagInner::lint_id` field
also gets merged in.
Specific nice things about this:
- Removes some unreachable match arms for `Allow`/`Expect`.
- Removes the hacky upgrading of `Allow`/`Expect` to `Warning` in
`emit_future_breakage_report`.
- The types now have structure that used to be maintained by comments
and assertions. E.g. it's now impossible to not have a `lint_id` for
an `expect` lint. (I always found the `DiagInner::lint_id` field
confusing; it's clearer now.)
- There's a nice comment on `EmissionOverride` summarizing all the
different cases.
- A little less code overall.
This is a part of the stack-protector work.
Adding support for merge-functions is not strictly needed, but it does
prevent breakage if the GCC function merging logic changes.
Not adding tests for -Z merge-functions since I don't see any such tests for the
LLVM side of it.
rustc_codegen_llvm: catch up with LLVM 24 on wasm exceptions
LLVM 24 [removed](cf40ab1dc1) the -wasm-enable-eh option in favor of relying on TargetMachine.Options.ExceptionModel == Wasm. We were already setting ExceptionModel to Wasm on LLVM 24 in PassWrapper.cpp for wasm targets so this is a no-op on LLVM 24. Further, we already implied the -wasm-enable-eh flag on LLVM 23, so the explicit pass in wasm-exceptions-nostd was redundant and can be safely dropped.
@rustbot label: +llvm-main
fix and test `va_arg` on `f128` on `x86`
tracking issue: https://github.com/rust-lang/rust/issues/116909
Or well, maybe not fix but clarify. There are no actual behavioral changes, but I do think the new code is more correct.
The clang logic for `va_arg` is kind of (weirdly) complicated. `EmitVAArg` looks simple, but the complexity is hiding in the "messing with TypeInfo" bit:
0e2786dcb5/clang/lib/CodeGen/Targets/X86.cpp (L1080-L1101)
```c++
RValue X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
QualType Ty, AggValueSlot Slot) const {
auto TypeInfo = getContext().getTypeInfoInChars(Ty);
CCState State(*const_cast<CGFunctionInfo *>(CGF.CurFnInfo));
ABIArgInfo AI = classifyArgumentType(Ty, State, /*ArgIndex*/ 0);
// Empty records are ignored for parameter passing purposes.
if (AI.isIgnore())
return Slot.asRValue();
// x86-32 changes the alignment of certain arguments on the stack.
//
// Just messing with TypeInfo like this works because we never pass
// anything indirectly.
TypeInfo.Align = CharUnits::fromQuantity(
getTypeStackAlignInBytes(Ty, TypeInfo.Align.getQuantity()));
return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo,
CharUnits::fromQuantity(4),
/*AllowHigherAlign*/ true, Slot);
}
```
Relevant for us is that it makes an exception for `f128`, for which a higher align (16, instead of the slot size of 4) is used.
0e2786dcb5/clang/lib/CodeGen/Targets/X86.cpp (L575-L583)
```c++
unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty,
unsigned Align) const {
// Otherwise, if the alignment is less than or equal to the minimum ABI
// alignment, just use the default; the backend will handle this.
if (Align <= MinABIStackAlignInBytes)
return 0; // Use default alignment.
if (Ty->isFloat128Type())
return 16;
```
Our code does not have this `TypeInfo` idea, and it's not correct in general to just use `AllowHigherAlign::Yes`. But using it only for `f128` works. We don't need to consider more complicated cases like structs containing `f128` fields.
The code here used `is_like_windows` before. I'm not exactly sure why, the behavior is the same for all accepted types, except now `f128`. But windows does not have that type, so its (c-variadic) ABI is just an LLVM fabrication. The x86 code does not seem to make a distinction based on the ABI, so having the same behavior across targets seems best to me.
`va_arg` to fetch an `i128` argument is currently broken in clang. `i128` on the target is apparently a clang extension anyway, so kind of low priority. `f128` I only fixed somewhat recently in https://github.com/llvm/llvm-project/pull/218017.
r? beetrees or @tgross35
(this may cause a small conflict with https://github.com/rust-lang/rust/pull/163021)
This patch refactors setup of the LegacyPassManager for CodeGen into a
single function. This simplifies some things (lifetime for the LegacyPM
object), but is primarily aimed at enabling rustc to use the new
runCodeGenPipeline abstraction (introduced in LLVM 24) which handles all
of these details within LLVM and additionally defaults to the NewPM when
a target opts-in/the correct LLVM flag is passed.
Build a new incr comp session dir from scratch every time
Rather than copying the old incr comp dir and then modifying it. This saves a copy/hardlink for files that are modified. And it removes the need for accurate work product tracking to avoid accumulating cruft, which is non-trivial. We don't accurately track the pre-LTO bitcode files for ThinLTO for example.
Part of https://github.com/rust-lang/compiler-team/issues/908
Rather than copying the old incr comp dir and then modifying it. This
saves a copy/hardlink for files that are modified. And it removes the
need for accurate work product tracking to avoid accumulating cruft,
which is non-trivial. We don't accurately track the pre-LTO bitcode
files for ThinLTO for example.
The existing code makes a separate FFI call to `MCSubtargetInfo::checkFeatures`
for each feature-dependency of the feature being checked, and also performs
string-manipulation on the C++ side to add a leading '+' to each feature name.
What we can do instead is prepare a single string on the Rust side in the form
`"+foo,+bar,+baz,"` for each Rust target feature, and pass that string to LLVM.
LLVM already knows how to check that all of the listed features are present.
(The trailing comma is not a problem, because `SubtargetFeatures::Split` will
automatically discard empty substrings after splitting on commas.)
Cleanup offload build steps
We used to generate a couple of artifacts only because clang offload tooling required them. Now that we fully control the build steps on the Rust side without clang tooling, we can remove most of them. I'll make a follow-up PR afterwards to also remove device.bin artifacts and pass the normal rustc outputs of the device compilation pass.
r? oli-obk
Both will be used by the amdgpu target to implement the `gpu-kernel`
ABI.
`address_space` specifies the address space of an indirect argument.
`AmdgpuKernelArg` translates to LLVM’s byref, which is similar to
on_stack/byval, however, there is no extra copy made, the pointer may
not point to the stack but can point to some other address space, and
the passed argument should not be modified.
byval and byref are mutually exclusive, so change on_stack to an enum
with the new states, Pointer (none), OnStack and AmdgpuKernelArg.
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.
LLVM 24 removed the -wasm-enable-eh option in favor of relying on
TargetMachine.Options.ExceptionModel == Wasm. We were already setting
ExceptionModel to Wasm on LLVM 24 in PassWrapper.cpp for wasm targets so
this is a no-op on LLVM 24. Further, we already implied the
-wasm-enable-eh flag on LLVM 23, so the explicit pass in
wasm-exceptions-nostd was redundant and can be safely dropped.
`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)
For production use, we should only link in the ubsan_minimal runtime,
instead of the complete ubsan runtime. This adds support for both
cfi-recover and cfi-diag to use the minimal runtime when
`-Zsanitizer-cfi-minimal-runtime` is specified.
This also includes tests, to ensure the flag can only be used if either
cfi-recover or cfi-diag is enabled, it doesn't disrupt the original
behavior, and links in the correct runtime when specified.
Co-Authored-By: Bastian Kersting <bkersting@google.com>
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.)
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