Commit Graph

3868 Commits

Author SHA1 Message Date
Jonathan Brouwer
99f6df7fc7 Rollup merge of #163574 - tgross35:intrinsics-abort-rename, r=clarfonthey
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.
2026-10-02 22:39:48 +02:00
Jonathan Brouwer
e70aee9ec7 Rollup merge of #163572 - cuviper:min-llvm-22, r=nikic
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
2026-10-02 22:39:44 +02:00
Trevor Gross
e9b0eeb99d 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`).
2026-10-02 18:56:41 +00:00
Josh Stone
c76b523860 Update the minimum external LLVM to 22
Co-authored-by: Augie Fackler <augie@google.com>
2026-10-02 09:21:16 -07:00
bors
da51be10c3 Auto merge of #158863 - WaffleLapkin:nonofree, r=RalfJung
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
2026-10-02 14:08:00 +00:00
Jacob Pratt
bc54083b65 Rollup merge of #162556 - boomanaiden154:rustc-legacy-pm-refactoring-9-9-26, r=cuviper
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.
2026-10-02 01:07:11 -04:00
Jonathan Brouwer
82402295e2 Rollup merge of #163405 - bjorn3:less_linkage_options, r=lqd
Remove some #[linkage] options

These are either useless due to rustc already setting them whenever you would want them, actively breaking compiler invariants or both.

cc https://github.com/rust-lang/rust/issues/29603#issuecomment-5847225623
2026-10-01 17:22:53 +02:00
bjorn3
d731edabc0 Remove #[linkage = "common"]
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]
2026-09-30 16:59:42 +02:00
Waffle Lapkin
6d2f74f4dc Emit llvm dereferenceable in more cases on newer LLVM versions
Specifically on llvm >= 23.0.0 emit llvm `dereferenceable` attribute even
without `nofree`, since new semantics allow that.
2026-09-30 11:23:49 +02:00
Mark Rousskov
4c11abbbd2 Step cfg(bootstrap) 2026-09-29 22:18:54 +00:00
Trevor Gross
538a927606 Rollup merge of #162493 - jakos-sec:ubsan-runtime-minimal, r=rcvalle
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
2026-09-28 23:20:40 -05:00
mejrs
d3d2163b20 dont store arbitrary parsed attributes in thir 2026-09-28 14:43:44 +02:00
Jacob Pratt
1d6d8b861b Rollup merge of #163307 - nnethercote:less-SpanData-in-diagnostics, r=bjorn3
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
2026-09-27 21:51:43 -04:00
Jonathan Brouwer
1c87a25d83 Rollup merge of #163250 - mejrs:hir_imports3, r=JonathanBrouwer
Remove rustc_hir's attribute re-exports

Followup to https://github.com/rust-lang/rust/pull/160336, see also rust-lang/rust#163170, rust-lang/rust#163207 and rust-lang/rust-clippy/pull/17714

Very minor touchups here and there, nothing involving code changes.

r? @JonathanBrouwer
2026-09-27 18:58:12 +02:00
Jacob Pratt
7756b3ed4a Rollup merge of #163290 - nnethercote:merge-warning-levels, r=oli-obk
Merge `ForceWarning`/`Allow`/`Expect` into `Warning`

Because they're all just special cases of warnings. Details in individual commits.

r? @oli-obk
2026-09-26 01:33:19 -04:00
Jacob Pratt
727dc4a4e8 Rollup merge of #163274 - arielb1:stack-protector-tests-gcc, r=GuillaumeGomez,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.
2026-09-26 01:33:18 -04:00
Nicholas Nethercote
fcf74ea737 Merge ForceWarning/Allow/Expect into Warning
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.
2026-09-26 07:47:13 +10:00
mejrs
564f208ba9 compiler: remove rustc_hir attr re-exports 2026-09-25 18:39:43 +02:00
Ariel Ben-Yehuda
5237e38fdd 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.
2026-09-25 15:17:18 +03:00
Jonathan Brouwer
3aedb62854 Rollup merge of #163113 - durin42:llvm-24-wasm-eh, r=nikic
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
2026-09-25 12:22:55 +02:00
Nicholas Nethercote
f01eea524c Remove the SpanData in InlineAsmError
By just storing `lo` and `hi` instead.
2026-09-25 16:13:26 +10:00
Jacob Pratt
a4a2aaea15 Rollup merge of #163037 - folkertdev:x86-vaarg-f128, r=beetrees
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)
2026-09-24 23:06:51 -04:00
Aiden Grossman
2160998a06 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.
2026-09-24 07:27:36 -07:00
bors
f340ff6a39 Auto merge of #163265 - JonathanBrouwer:rollup-RZQ8eQg, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163218 (stdarch subtree update)
 - rust-lang/rust#159287 (Build a new incr comp session dir from scratch every time)
 - rust-lang/rust#163222 (Enable EII tests for cg_gcc)
 - rust-lang/rust#163251 (cg_gcc subtree sync 2026-09-24)
 - rust-lang/rust#162595 (avoid accessing uninferred closure upvars in diagnostics)
 - rust-lang/rust#162937 (do generic_const_args Const::Ty hack only on projection consts)
 - rust-lang/rust#163238 (Fix incorrect use of await in parser suggestion)
2026-09-24 14:19:04 +00:00
Jonathan Brouwer
f0f6653e3b Rollup merge of #159287 - bjorn3:incr_comp_session_from_scratch, r=nnethercote
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
2026-09-24 16:05:26 +02:00
bjorn3
5ed0180b64 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.
2026-09-24 12:34:06 +02:00
Jonathan Brouwer
c092ef06c3 Rollup merge of #163214 - malezjaa:revert-r14-register-name, r=folkertdev
revert r14 register names for arm

Fixes rust-lang/rust#163173

r? @folkertdev
2026-09-24 09:38:17 +02:00
Zalathar
733daee361 Use fewer FFI calls to check the target CPU's features
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.)
2026-09-24 10:58:50 +10:00
malezjaa
b7dc072006 revert r14 register names for arm 2026-09-23 15:08:43 +02:00
Jonathan Brouwer
e43f8c5da0 Rollup merge of #163179 - ZuseZ4:cleanup-offload, r=bjorn3
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
2026-09-23 13:43:18 +02:00
Flakebi
039b8bcadc Add address_space and byref to abi PassMode::Indirect
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.
2026-09-23 09:56:28 +02:00
Manuel Drehwald
4f20be3135 also drop now unused host.o 2026-09-22 16:50:51 -04:00
Manuel Drehwald
9b9cb70640 Stop embedding device code, now that the clang-linker-wrapper isn't consuming it anymore 2026-09-22 16:44:04 -04:00
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
Augie Fackler
9acb7866d4 rustc_codegen_llvm: catch up with LLVM 24 on wasm exceptions
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.
2026-09-21 10:16:30 -04: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
Folkert de Vries
3285cce3da fix va_arg on f128 on x86 2026-09-21 13:41:43 +02:00
Jakob Koschel
8e5ad6c1e4 use match to determine correct ubsan cfi handler 2026-09-21 11:14:06 +00:00
Jakob Koschel
1bd00d4f72 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.

Co-Authored-By: Bastian Kersting <bkersting@google.com>
2026-09-21 09:43:59 +00: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