Commit Graph

3917 Commits

Author SHA1 Message Date
Guillaume Gomez dc05df7ebe Rollup merge of #157022 - RalfJung:inline-intrinsics-v2, r=oli-obk
MIR inlining: allow backends to opt-in to inlining intrinsics

This is the same as https://github.com/rust-lang/rust/pull/156398. Github stopped processing updates on that other branch.

r? @oli-obk
2026-05-27 20:45:10 +02:00
Ralf Jung 59428e76e8 MIR inlining: allow backends to opt-in to inlining intrinsics 2026-05-27 13:59:25 +02:00
Jonathan Brouwer aa9d13374b Rollup merge of #156814 - cezarbbb:fix-issue-156714, r=jieyouxu
Extend macOS deployment target mismatch filter to cover dylib and new ld formats

The `deployment_mismatch` filter in `report_linker_output` only matched the old ld64 format for object files. With linker-messages promoted to warn-by-default in rust-lang/rust#153968, unfiltered deployment target warnings from dylibs and the new Apple linker (ld_prime) now surface as noise for users who never set `MACOSX_DEPLOYMENT_TARGET`.

Fixes rust-lang/rust#156714.

At present, the filter works only covered the specific format:

`ld: warning: object file (...) was built for newer 'macOS' version (...) than being linked (...)`

This was fine because linker-messages was `Allow-by-default` — nobody saw the other formats anyway. Then rust-lang/rust#153968 promoted it to Warn, and the gaps became visible.

Broadens the filter to cover all known ld deployment target version mismatch formats:

`ld: warning: object file (...)` — old ld64, already handled
`ld: warning: dylib (...)` — old ld64, was missing
All Apple platforms (`iOS`, `tvOS`, `watchOS`, `xrOS`, etc.), not just `macOS`
`ld: building for <platform>-A.B, but linking with dylib '...' which was built for newer version C.D` — new linker (ld_prime, Xcode 15+), the exact format from rust-lang/rust#156714

All matched messages are downgraded to `linker_info` (Allow-by-default), consistent with the existing behavior for the object file case.
2026-05-27 08:14:26 +02:00
cezarbbb 52bedb4c05 Suppress macOS deployment target linker warnings from ld_prime 2026-05-27 11:32:09 +08:00
bors 23a3312d92 Auto merge of #156116 - scottmcm:tweak-layout-of-alternative, r=dianqk
Stop needing materialized places for most intrinsics



Today even to return a constant from `size_of_val` it takes an `alloca`.  That's wasteful.

This updates the cg_ssa traits to allow returning an `OperandValue` instead, which is possible for the vast majority of intrinsics -- this PR moves all but 5 over to doing that in LLVM.

The first commit adds a test to help show the difference here.

cc https://github.com/rust-lang/compiler-team/issues/970 https://github.com/rust-lang/rust/issues/153250
2026-05-23 19:23:06 +00:00
Scott McMurray d3d3485dd4 Let intrinsics use the SSA operand path 2026-05-22 22:02:06 -07:00
Jonathan Brouwer 7ab3168371 Rollup merge of #152821 - wesleywiser:add_forbidden_ctarget_feature_hard_error_option, r=dingxiangfei2009
Allow forbidden target features to be hard errors

Sometimes when adding a new target features to the list of known target features, we want to completely forbid them from being used because they are ABI affecting and should be target modifiers instead. As such, we want to issue an error rather than a warning since there are no future compatibility concerns .

r? @workingjubilee since you're familiar with the motivating case in rust-lang/rust#136597

If I rebase that PR on top of this locally, then we get the following error messages when trying to activate the SLS target feature (note that they are *errors* not *warnings* and we've omitted the usual note about future compatibility):

```
error: target feature `harden-sls-ijmp` cannot be enabled with `-Ctarget-feature`: use `harden-sls` compiler flag instead

error: target feature `harden-sls-ret` cannot be enabled with `-Ctarget-feature`: use `harden-sls` compiler flag instead

error: aborting due to 2 previous errors
```
2026-05-22 16:21:26 +02:00
Jonathan Brouwer 8162cf582b Rollup merge of #156242 - Jamesbarford:feat/remove-alwaysinline+target-feature, r=RalfJung,saethlin
Remove unsound `target_feature_inline_always` feature

## Summary
- Remove `target_feature_inline_always`
- Update stdarch generators to only use `#[inline]` & regenerate stdarch.

## Why?
Succinctly; the feature relies on LLVMs `AlwaysInlinerPass()` running before LLVMs heuristic based inliner pass. Which is not a basis for sound code.

This has been discussed in [the tracking issue](https://github.com/rust-lang/rust/issues/145574).

If the ordering of the passes were to change, of which they have in the past, it is very possible we could inline functions across callsites with mismatching target features leading to unsound code. Checks proposed in; https://github.com/rust-lang/rust/pull/155426 would only take into account caller -> callee which is not enough to guard against possibly of generating unsound code if the pass ordering were to change.

There doesn't seem to be a way, presently, this this mechanism to provide soundness guarantees nor does it seem like `AlwaysInlinerPass()` is a desired feature of LLVM, which this feature relies on.

r? @RalfJung
2026-05-21 12:21:45 +02:00
Jonathan Brouwer b0c869a35e Rollup merge of #156596 - nnethercote:split-LintExpectation, r=GuillaumeGomez
Split `LintExpectationId`s

This PR makes clearer where stable and unstable `LintExpectationIds` can occur, plus a few other small cleanups. Details in individual commits.

r? @GuillaumeGomez
2026-05-17 15:52:37 +02:00
Jonathan Brouwer ff42fc00d4 Rollup merge of #156208 - BorrowSanitizer:codegen-emit-retag-1, r=saethlin
Emit retags in codegen to support BorrowSanitizer (part 1)

Tracking issue: rust-lang/rust#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/593004012)

This is the first of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in rust-lang/rust#155965.

This PR contains all of the changes that will affect codegen backends. It adds methods to `IntrinsicCallBuilderMethods` for emitting each kind of retag call.

cc: @RalfJung
2026-05-17 15:52:36 +02:00
bors 281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
Nicholas Nethercote 22cf1fb6fe Split LintExpectationId
`LintExpectationId` has two variants, `Unstable` and `Stable`. There are
some places where both variants are possible, but there are also places
where only one of `Unstable` or `Stable` is possible.

This commit encodes this into the type system by introducing
new types `UnstableLintExpectationId` and `StableLintExpectationId`. The
variants of `LintExpectationId` now enclose these. This makes it clearer
what values are possible where.

Other things of note:
- `LintLevelsProvider` gets an associated type and some method changes.
- `LintContext` gets an associated type.
- `LevelSpec` is made generic. `UnstableLevelSpec` and `StableLevelSpec`
  typedefs are added.
- The unstable types are now guaranteed by the type system to never be
  stably hashed. Previously this was a runtime check.
2026-05-16 21:16:35 +10:00
Ian McCormack e15861bdd2 Add trait methods for experimental retags to cg. 2026-05-15 12:34:03 -04:00
James Barford-Evans 812e230fb9 PR Feedback - grammatical changes, clear reason for removal and move register_removed(...) call 2026-05-14 11:11:55 +01:00
Nicholas Nethercote ccfac5469a Rename LevelAndSource
It is misnamed, given that it has three fields: `level`, `lint_id`, and
`src`. (Presumably the `lint_id` was added later.)

This commit renames it as `LevelSpec`. (I also considered `LevelInfo`
but that's very generic. `Spec` has pre-existing uses in
`LintLevelsProvider::current_specs` and `LintSet::specs` and
`ShallowLintLevelMap::specs`.)

Related things renamed as well:
- `level` -> `level_spec` (where appropriate)
- `lint_levels` -> `lint_level_specs`
- `get_lint_level` -> `get_lint_level_spec`
- `level_and_source` -> `level_spec`
- `CodegenLintLevels` -> `CodegenLintLevelSpecs`
- `raw_lint_id_level` -> `raw_lint_level_spec`
- `lint_level_at_node` -> `lint_level_spec_at_node`
- `reveal_actual_level` -> `reveal_actual_level_spec`
- `probe_for_lint_level` -> `probe_for_lint_level_spec`

This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more
`level.level` expressions.
2026-05-14 13:20:57 +10:00
Jonathan Brouwer 8edd846028 Rollup merge of #156472 - stephenduong1004:print-stats-json, r=nikomatsakis
Add support for Zprint-codegen-stats-json

Add a flag `-Zprint-codegen-stats-json=<file>` to collect and write LLVM statistics in JSON format. It makes use of the function `llvm::PrintStatisticsJSON` in LLVM.

The flag currently only obtains LLVM statistics for now, but could be used to collect more front-end statistics in the future.
2026-05-13 11:46:37 +02:00
Esteban Küber 31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
bors c8c4c83d57 Auto merge of #156224 - khyperia:unnormalized-migration, r=BoxyUwU
Unnormalized migration: assert_fully_normalized, struct_tail, and `field.ty`



tracking issue: https://github.com/rust-lang/rust/issues/155345 (first checkbox, and partial second checkbox, of that issue)

I'm going a bit slower than expected (less free time than I'd hope, lots of GCA work that I'm doing instead), and figured I'd just submit what I have now rather than building up a big batch of changes. Slow and steady!

r? @lcnr
2026-05-13 00:16:00 +00:00
khyperia 869c941be9 Unnormalized migration: introduce assert_fully_normalized 2026-05-12 20:45:13 +02:00
Jonathan Brouwer 4ce7ac120c Rollup merge of #156287 - cyrgani:unbox-2, r=petrochenkov
move more compiler crates away from `box_patterns`

Part of https://github.com/rust-lang/rust/issues/156110.
2026-05-12 18:53:35 +02:00
Stephen 8477a690b1 add support for Zprint-codegen-stats-json 2026-05-11 16:28:51 -04:00
cyrgani a06037901c use deref_patterns in rustc_codegen_ssa 2026-05-10 21:05:37 +00:00
Jonathan Brouwer 5246f6e4bc Rollup merge of #156323 - bjorn3:clif_has_mnemonic, r=wesleywiser
Handle --print=backend-has-mnemonic in cg_clif

And introduce a `has_mnemonic` method on `CodegenBackend` just like `--print=backend-has-zstd`.
2026-05-10 19:05:44 +02:00
Jonathan Brouwer 30ec142b97 Rollup merge of #154972 - chorman0773:return_address, r=Mark-Simulacrum
Implement `core::arch::return_address` and tests

Tracking issue: rust-lang/rust#154966

Implements libs-team#768
2026-05-10 19:05:42 +02:00
Jacob Pratt 71e64b9d25 Rollup merge of #156124 - nnethercote:StableHash-renamings-2, r=jieyouxu
Make stable hashing names consistent (part 2)

This PR finishes the implementation of MCP 893.

r? @jieyouxu
2026-05-09 09:27:58 -04:00
Jonathan Brouwer fbc52c9ecf Rollup merge of #156291 - kupiakos:msvc-link-info, r=jyn514,mati865
Treat MSVC "performing full link" message as informational

When the MSVC incremental linker finds a .ilk file for incremental linking but its associated .exe file is missing, this message is printed to stdout:

```text
LINK : ...\foo.exe not found or not build by the last incremental link; performing full link
```

However, if both the .ilk and .exe files are missing (for a clean build), the message isn't printed and it still does a full link. So, the presence of the message doesn't affect the result of the build.

See rust-lang/rust#156209 for further context.

r? @mati865
cc @jyn514
2026-05-08 16:18:41 +02:00
bjorn3 c2ab95fb61 Handle --print=backend-has-mnemonic in cg_clif
And introduce a has_mnemonic method on CodegenBackend just like
--print=backend-has-zstd
2026-05-08 16:08:56 +02:00
Nicholas Nethercote 33cd10a881 Rename rustc_data_structures::stable_hasher as stable_hash.
Part of MCP 983.
2026-05-08 15:10:33 +10:00
Alyssa Haroldsen 39c766e310 Treat MSVC "performing full link" message as informational
When the MSVC incremental linker finds a .ilk file for incremental
linking but its associated .exe file is missing, this message is
printed to stdout in 1 line:

LINK : ...\foo.exe not found or not build by the last incremental link;
performing full link

However, if both the .ilk and .exe files are missing (for a clean
build), the message isn't printed and it still does a full link. So, the
presence of the message doesn't affect the result of the build.
2026-05-07 13:59:23 -07:00
Jonathan Brouwer 05c012fff5 Rollup merge of #156198 - Zoxc:threads-sync, r=folkertdev
Add `sync` option to `-Z threads` to force synchronization on one thread

This adds a `sync` option to `-Z threads` to force synchronization while still using one thread. This is useful to measure overhead of synchronization without the noise of additional threads.
2026-05-07 22:44:06 +02:00
Aapo Alasuutari 2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
Jonathan Brouwer a48901b65b Rollup merge of #156245 - bjorn3:move_invocation_temp, r=oli-obk
Move invocation_temp into OutputFilenames

While it was previously defined in Session, it is only ever used with OutputFilenames methods.
2026-05-07 14:13:54 +02:00
Jonathan Brouwer c5941a03a2 Rollup merge of #156243 - bjorn3:lto_refactors18, r=mu001999
Move CrateInfo computation after codegen_crate

CrateInfo is only necessary during linking and non-local LTO.

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-05-07 14:13:51 +02:00
Jonathan Brouwer 25494215e7 Rollup merge of #156024 - rcvalle:rust-cfi-fix-142284, r=bjorn3
CFI: Fix LTO for `#![no_builtins]` crates with CFI

Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's `EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for linker-based LTO).

It also adds tests that verify that the examples in [rust-cfi-examples](https://github.com/rcvalle/rust-cfi-examples) build and run with `-Zbuild-std` to prevent other future regressions.
2026-05-07 14:13:51 +02:00
James Barford-Evans c6d2da90b5 Remove #[inline(always)] + #[target_feature(enable = "<feature>")] support, reinstating error message and providing a link to the tracking issue for the full rationale. 2026-05-07 08:28:09 +01:00
Wesley Wiser 63d1985d38 Allow forbidden target features to be hard errors 2026-05-06 21:10:15 -05:00
bors 4ddd4538a8 Auto merge of #154327 - WaffleLapkin:drop_in_place_ref, r=RalfJung,scottmcm,saethlin
change the type of the argument of `drop_in_place` lang item to `&mut _`



We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:

https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392

This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:

https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833

------

The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?

I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)

-------

cc @RalfJung 
Closes https://github.com/rust-lang/rust/issues/154274
2026-05-07 00:52:53 +00:00
John Kåre Alsaker 8aafed8a17 Add sync option to -Z threads to force synchronization on one thread 2026-05-07 02:06:18 +02:00
Ramon de C Valle acc33fe5dd CFI: Fix LTO for #![no_builtins] crates with CFI
Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's
`EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for
linker-based LTO).
2026-05-06 13:44:04 -07:00
bjorn3 9297586cb9 Move invocation_temp into OutputFilenames
While it was previously defined in Session, it is only ever used with
OutputFilenames methods.
2026-05-06 15:01:54 +00:00
bjorn3 da6e4d4890 Move CrateInfo computation after codegen_crate
CrateInfo is only necessary during linking and non-local LTO.
2026-05-06 14:51:38 +00:00
Jacob Pratt b594ef31e9 Rollup merge of #156174 - daxpedda:wasm-clear-exports, r=alexcrichton
Wasm: remove implicit `__heap_base`/`__data_end` exports

This is kind of a follow-up to rust-lang/rust#147225. Currently `__heap_base`/`__data_end` globals are implicitly exported on `wasm*-unknown-unknown` and `wasm32v1-none`, even though they were only used for Wasm multi-threading, requiring the atomics target feature and shared memory.

Instead users should explicitly opt-in to these features, in which case toolchains, like `wasm-bindgen`, would require some linker flags. After this PR the following would be required for multi-threading support in `wasm-bindgen`:
```
-Clink-arg=--shared-memory -Clink-arg=--max-memory=1073741824 -Clink-arg=--import-memory -Clink-arg=--export=__heap_base -Clink-arg=--export=__wasm_init_tls -Clink-arg=--export=__tls_size -Clink-arg=--export=__tls_align -Clink-arg=--export=__tls_base
```

You will notice that the only new addition is `--export=__heap_base`, apparently `wasm-bindgen` doesn't need `__data_end` anymore (I didn't dig into the original motivation).

---

For context why `wasm-bindgen` needed access to `__heap_base`:
There is currently no mechanism in the Wasm tool conventions that automatically allocates the stack for every thread (e.g. via the `start` function). So `wasm-bindgen` has to explicitly call `malloc` to allocate the stack on the new thread.

However, calling `malloc` itself requires a stack to be present! With the help of `__heap_base` `wasm-bindgen` constructs a temporary stack to make this work. This is obviously quite hacky. A newer implementation could go a different route: e.g. allocate the threads stack in the main thread and passing the right information on, not requiring access to `__heap_base` at all (and avoiding this really messy workaround).

I should also note here that e.g. [`js-bindgen`](https://github.com/wasm-bindgen/js-bindgen), the successor currently being worked on, doesn't need any of these exports because it doesn't rely on post-processing. In which case all of these variables can be accessed by name at link-time, instead of requiring the linker to export each variable for post-processing to find them by name. That is to say: all these workaround are toolchain-specific and not universal to the Wasm targets.

---

r? @alexcrichton
2026-05-05 22:50:21 -04:00
bors 740679e1f5 Auto merge of #154861 - mehdiakiki:fix/rlib-digest, r=petrochenkov
Add rlib digest to identify Rust object files



This adds a metadata entry to `rlib` archives that lists which members are Rust object files instead of relying on the filename heuristic in `looks_like_rust_object.file`. I also added a fallback to the old behavior for `rlibs` built by older compilers. 

Part of https://github.com/rust-lang/rust/issues/138243.
2026-05-05 16:26:33 +00:00
Waffle Lapkin 810eae99af rename drop_in_place lang item to drop_glue 2026-05-05 12:36:39 +02:00
daxpedda fbb5809996 Wasm: remove implicit __heap_base/__data_end exports 2026-05-05 07:21:22 +02:00
mehdiakiki 9606b0bd77 Add rlib digest to identify Rust object files 2026-05-04 21:55:47 -04:00
Guillaume Gomez 8bf58ee5d4 Rollup merge of #155962 - romancardenas:cfg-only-stable-target-feature, r=RalfJung
`rustc`: `target_features`: allow for `cfg`-only stable `target_features`

This PR introduces a new stabilization level for `target_features`: `CfgOnlyStable`. The motivation is allowing the Rust compiler to expose `target_features` of targets so users can use `cfg(target_feature = "feature")` for conditional blocks depending on target features. However, `CfgOnlyStable` cannot be used for `#[target_feature(enable = "feature")]`, as this is still considered unstable. Accordingly, the compiler will still raise an error if these expressions are used on stable.

This PR relates partially to rust-lang/rust#150257. As discussed, for RISC-V targets, having the `"d"`, `"e"`, and `"f"` target features exposed will allow baremetal developers to adapt the code depending on the target's properties.

r? @RalfJung
2026-05-05 02:50:08 +02:00
Román Cárdenas Rodríguez ee9a01aecf rustc: target_features: adapt compile errors and warnings for cfg-only stable features 2026-05-04 17:28:35 +02:00
Román Cárdenas Rodríguez df8d029014 rustc: target_features: allow for cfg-only stable target_features 2026-05-04 10:12:27 +02:00
Jacob Pratt c3afa21a40 Rollup merge of #156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind

Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2026-05-03 00:25:33 -04:00