Commit Graph

516 Commits

Author SHA1 Message Date
Jonathan Brouwer
87749cea75 Rollup merge of #157588 - scottmcm:copy-nsuw, r=saethlin
Use `mul nuw nsw` in `intrinsics::copy`

Essentially the same as rust-lang/rust#157560, just for `copy` instead of `copy_nonoverlapping`.

> Yeah, in fact both copy and copy_nonoverlapping could use this since we know the result must be at most isize::MAX else it cannot be inbounds.
> ~ https://github.com/rust-lang/rust/pull/157560#issuecomment-4642072687

r? saethlin
2026-06-08 09:41:58 +02:00
Scott McMurray
871664e02a Also use mul nuw nsw in intrinsics::copy
Essentially the same as 157560, just for `copy` instead of `copy_nonoverlapping`.
2026-06-07 16:57:55 -07:00
Jacob Pratt
753665aff6 Rollup merge of #157560 - scottmcm:mul_nuw_nsw_in_memcpy, r=saethlin
In `copy_nonoverlapping`, use `mul nuw nsw` to compute the byte size

Seems like we might as well?  Adding these flags means the optimizer can tell the limited range on the count of items -- like how we use these flags (rust-lang/rust#136575) when calculating `size_of_val` for a slice.

Today we use a wrapping multiplication, which mean that `copy_nonoverlapping::<u32>(src, dst, 0x40000000_00000001)` appears like 4 bytes -- a perfectly reasonable size! -- once it gets to the `memcpy` call.

If I'm understanding <https://doc.rust-lang.org/std/ptr/fn.copy_nonoverlapping.html#safety> properly, this is just exploiting existing UB, since `src` and `dst` must each be inside an allocation, and those allocations can be at most `isize::MAX` bytes.  (Plus, fundamentally, to be non-overlapping there's not enough space in the address space to be bigger than `isize::MAX`.)

cc @RalfJung to make sure this is ok, as requested last he found out I was newly exploiting some UB in codegen 🙃
r? codegen
2026-06-07 17:47:55 -04:00
Jacob Pratt
0efcd77acb Rollup merge of #156119 - Kmeakin:km/optimize-str-index, r=Mark-Simulacrum
Further optimize `SliceIndex<str>` impl for `Range<usize>`

We can shave a further 2 `icmp`s by inlining `is_char_boundary` and rearranging the checks.

Follow up to https://github.com/rust-lang/rust/pull/145024
2026-06-07 17:47:42 -04:00
bors
f20a92ec01 Auto merge of #147250 - Kmeakin:km/optimize-ilog-base-power-of-two, r=jhpratt
Optimize `checked_ilog` and `pow` when `base` is a power of two



Optimize `checked_ilog` and `pow` when the base is a power of two
2026-06-07 18:31:31 +00:00
Scott McMurray
4af2ca0a93 In copy_nonoverlapping, use mul nuw nsw to compute the byte count 2026-06-06 21:57:35 -07:00
Jacob Pratt
534d42c318 Rollup merge of #157365 - zmodem:revert_assign_guids, r=cuviper
Revert "LLVM 23: Run AssignGUIDPass in some places"

This reverts commit cdb73bb677.

The LLVM side change was reverted.
2026-06-07 00:37:56 -04:00
Folkert de Vries
4e59f4c54b add extern "tail" calling convention 2026-06-05 20:19:51 +02:00
Hans Wennborg
4919940fad Revert "LLVM 23: Run AssignGUIDPass in some places"
This reverts commit cdb73bb677.
2026-06-05 09:26:08 +02:00
bors
688ab44c74 Auto merge of #157440 - JonathanBrouwer:rollup-XlcBgjV, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#156281 (Emit nofree attribute)
 - rust-lang/rust#157305 (Eagerly decide whether relaxed bounds are allowed or not)
 - rust-lang/rust#148713 (rustc_borrowck: fix async closure error note to report AsyncFn rather than Fn)
 - rust-lang/rust#156266 (Don't ICE in has_self_borrows when coroutine captures-by-ref ty is still inferred)
 - rust-lang/rust#156417 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait is not implemented)
 - rust-lang/rust#156956 (Support generic params in `Lift_Generic`)
 - rust-lang/rust#157140 ( rustc_target: Use rustc_abi instead of cfg_abi to detect powerpcspe )
 - rust-lang/rust#157423 (Refactor/expand rustc_attr_parsing docs)
2026-06-04 17:25:32 +00:00
Jonathan Brouwer
3ac83ceb48 Rollup merge of #156281 - nikic:nofree, r=RalfJung
Emit nofree attribute

Treat the semantics of pointee.size as "dereferenceable-at-point" and always specify the size. Instead, use a separate NoFree attribute to determine whether dereferenceability extends to the whole function.

Then in the LLVM backend, only actually emit dereferenceable if nofree is also set, as dereferenceable currently implies nofree.

In addition, explicitly emit the nofree attribute, which will help when LLVM switches dereferenceable to be at-point.

Relevant recent LLVM PR: https://github.com/llvm/llvm-project/pull/195658
2026-06-04 18:28:47 +02:00
Jonathan Brouwer
1fb3963888 Rollup merge of #157249 - vadorovsky:vad/llvm-codegen-bpf-alu32, r=nikic
tests: codegen-llvm: Update bpf-alu32 with the new LLVM attributes

The LLVM backend now emits `noundef zeroext` on `i8` return values and `noundef` on `i8` parameters. Update the FileCheck pattern to match.

r? @nagisa
2026-06-04 15:33:25 +02:00
Nikita Popov
cb09a42d7e Emit nofree attribute
Treat the semantics of pointee.size as "dereferenceable-at-point"
and always specify the size. Instead, use a separate NoFree attribute
to determine whether dereferenceability extends to the whole function.

Then in the LLVM backend, only actually emit dereferenceable if
nofree is also set, as dereferenceable currently implies nofree.

In addition, explicitly emit the nofree attribute, which will help
when LLVM switches dereferenceable to be at-point.
2026-06-04 15:19:24 +02:00
vad
177a0ece74 tests: codegen-llvm: Add -C opt-level=0 to bpf-alu32 test
Make sure that optimizations don't affect the resulting IR.
2026-06-03 12:56:07 +02:00
vad
1df9b8af17 tests: codegen-llvm: Check whether feature is emitted in bpf-alu32 test
Check whether the `"target-feature"` attribure was actually emitted in
LLVM IR.
2026-06-03 12:54:05 +02:00
vad
6a1b87296e tests: codegen-llvm: Use minicore in bpf-alu32
Instead of keeping it as `only-bpf`, use minicore. This way we make sure
it will never get outdated again.
2026-06-03 12:52:52 +02:00
vad
5cdf648eb5 tests: codegen-llvm: Allow additional LLVM attributes in bpf-alu32
The LLVM backend now emits `noundef zeroext` on `i8` return values and
`noundef` on `i8` parameters. Update the FileCheck pattern to match
those, and any possible future attributes.
2026-06-03 12:51:47 +02:00
bjorn3
9b7623a162 Remove -Zemscripten-wasm-eh
This was necessary when transitioning from JS to wasm exception handling
on Emscripten. Enough time has probably passed that we no longer need to
support JS exception handling on Emscripten. This enables cleaning up a
fair bit of code.
2026-06-02 19:56:40 +02:00
Jonathan Brouwer
94fee53bdf Rollup merge of #156467 - RalfJung:weak-import-addr, r=bjorn3
mark the 'import linkage' statics as unnamed_addr
2026-06-02 13:20:45 +02:00
Jonathan Brouwer
0f6fb22448 Rollup merge of #157055 - TimNN:guid, r=cuviper
LLVM 23: Run AssignGUIDPass in some places

https://github.com/llvm/llvm-project/pull/184065 introduced the new pass.

I'm not 100% confident that this is the correct patch, but it makes all the previously failing `run-make` "lto" tests pass on my machine.

I added the pass to the `if (NeedThinLTOBufferPasses)` section to match the `addRequiredLTOPreLinkPasses` changes from the LLVM PR, and to the `LLVMRustModuleSerialize` section based on the stack trace of an LLVM assertion.

The IR may now contain an additional `!guid` attribute, requiring some codegen test expectations to be updated. I mostly followed the pattern from the LLVM PR, and removed trailing `{`s. (For both, tests that were failing locally, as well as potentially problematic expectations identified via grep, in case the test wasn't being run locally).

@rustbot label llvm-main
2026-06-01 19:35:50 +02:00
Jonathan Brouwer
a5f745740f Rollup merge of #156887 - zamazan4ik:rename-debuginfo-for-profiling-switch, r=folkertdev
Rename `-Zdebuginfo-for-profiling` switch

The PR was raised from this [comment](https://github.com/rust-lang/rust/pull/155942#discussion_r3188023601) from another stabilization PR: https://github.com/rust-lang/rust/pull/155942

I renamed `-Zdebug-info-for-profiling` into `-Zdebuginfo-for-profiling` before stabilization to be consistent with other `debuginfo`-related Rustc flags like `-C split-debuginfo` and `-C debuginfo`.

One important note is that Clang has the [flag](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fdebug-info-for-profiling) under `-fdebug-info-for-profiling`. I decided that consistency with other Rustc flags is more important here than to be consistent with Clang.

r? folkertdev (as was proposed [here](https://github.com/rust-lang/rust/pull/155942#issuecomment-4527927374))
2026-05-30 18:01:55 +02:00
Jonathan Brouwer
213551d7e2 Rollup merge of #156863 - saethlin:silly-cold-path, r=jackh726
Make hint::cold_path #[cold] so that it works even if the MIR inliner can't inline it

This fixes https://github.com/rust-lang/rust/issues/156859 because the branch weight metadata is actually keyed off seeing a `#[cold]` function call in an arm. We don't need the intrinsic, any `#[cold]` function will do. So if the hint wrapper itself is made `#[cold]`, we will still get the desired effect, and LLVM will clean up the call to an empty function when optimizations are enabled.
2026-05-30 18:01:51 +02:00
Jonathan Brouwer
cbc3a2e0cf Rollup merge of #154835 - ZuseZ4:offload-sharedmem, r=oli-obk
std::offload sharedmem

@Sa4dUs @Kevinsala This simply allows requesting shared-memory for gpu kernels at launch time via std::offload. The actual work to access the shared memory inside the kernel has already landed independent of the offload work in rustc, so we're building on that.

cc @Flakebi (thanks for your work!)
2026-05-29 21:03:30 +02:00
Jonathan Brouwer
1e2fc47f29 Rollup merge of #156980 - Darksonn:frame-ptrs-module, r=nnethercote
Add frame pointer annotations to the module

While working on rust-lang/rust#156973 I found https://github.com/llvm/llvm-project/issues/188234 which points out that the frame pointer annotation is also missing.
2026-05-29 09:06:23 +02:00
Jonathan Brouwer
0f27774436 Rollup merge of #156867 - scottmcm:WIP-no-alloca-for-catch-unwind, r=dianqk
Stop needing an alloca for `catch_unwind`

Turns out these were all making `OperandValue::Immediate`s already -- the intrinsic always returns a primitive scalar -- so pretty easy to handle.

cc https://github.com/rust-lang/rust/issues/153250 https://github.com/rust-lang/compiler-team/issues/970

While I was looking at it, I also "rustified" the intrinsic signature a bit: returning a `bool` and taking a generic pointee and `unsafe fn`s cleans up the call in `std` a bit without making the implementation in the backend any harder.

r? dianqk
2026-05-29 09:06:19 +02:00
Alexander Zaitsev
fe17ed58e9 feat: add tests for debuginfo-for-profiling
- the test was ported from this commit: 3009211573
2026-05-29 07:28:43 +02:00
Scott McMurray
6aa9c0325e Stop needing an alloca for catch_unwind
Turns out these were all making `OperandValue::Immediate`s already -- the intrinsic always returns a primitive scalar -- so pretty easy to handle.

While I was looking at it, I also "rustified" the intrinsic signature a bit: returning a `bool` and taking a generic pointee and `unsafe fn`s cleans up the call in `std` a bit without making the implementation in the backend any harder.
2026-05-28 19:53:59 -07:00
Manuel Drehwald
c01bfdc405 Enable requesting shared-memory at kernel launch-time via offload 2026-05-28 16:03:06 -07:00
Tim Neumann
cdb73bb677 LLVM 23: Run AssignGUIDPass in some places 2026-05-28 13:30:25 +02:00
Alice Ryhl
df84feacbd Add frame pointer annotations to the module 2026-05-28 05:57:11 +00:00
Guillaume Gomez
0846622465 Rollup merge of #156973 - Darksonn:unwind-tables-module, r=nnethercote
Add uwtable annotation to modules when required

When unwind tables are enabled with `-Cforce-unwind-tables=y`, Rust will annotate all functions with the `uwtable` annotation. However, this annotation is missing on modules, which leads to incorrect unwind tables being generated by LLVM for constructors (such as `asan.module_ctor`).

This was discovered because it leads to a crash in Linux when KASAN and dynamic shadow call stack are both enabled. In this scenario, the kernel uses the unwind tables to locate the `paciasp` and `autiasp` instructions in each function and patches the machine code at boot to use the shadow call stack instructions instead. However, LLVM's AArch64PointerAuth pass emits DWARF info for `paciasp` whenever `-g` is passed, but only emits DWARF info for `autiasp` when the `uwtable` attribute is present. Since the `uwtable` annotation is missing for modules, the relevant directives are generated for only the `autiasp` instruction in `asan.module_ctor`, and not for the `paciasp` instruction. This causes the kernel's dynamic SCS logic to patch the prolouge of `asan.module_ctor`, but not the epilogue. This leads to a crash as the shadow call stack becomes unbalanced.

The fact that LLVM doesn't use the same condition for whether to emit DWARF information for both instructions may be a separate bug in LLVM.

Relevant issue: https://github.com/llvm/llvm-project/issues/188234

AI assistance was used to determine the root cause of this crash from the observed symptoms, and to write the tests. Also thanks to @samitolvanen and @maurer for debugging this issue.

Similar to this previous PR of mine: rust-lang/rust#130824
2026-05-27 20:45:14 +02:00
Alice Ryhl
581bf3c2f9 Add tests for uwtable annotations on modules 2026-05-26 14:43:44 +00:00
Jonathan Brouwer
04873a08af Rollup merge of #156878 - qaijuang:sve-tuple-intrinsics-filecheck, r=workingjubilee
codegen: re-enable FileCheck for scalable-vector tuple intrinsics

The FileCheck directives in `tests/codegen-llvm/scalable-vectors/tuple-intrinsics.rs` were not actually being checked: the test used `//@ build-pass`, and rust-lang/rust#155630 made that explicit by replacing it with `//@ skip-filecheck`.

This fixes the stale checks and re-enables FileCheck for the test. The `get` and `set` cases now use concrete index-0 wrappers, so they have stable `#[no_mangle]` names for FileCheck to match.

Fixes rust-lang/rust#155665.

r? @jieyouxu
2026-05-25 20:54:08 +02:00
Zalathar
028b8b6c54 Simplify //@ needs-asm-mnemonic: ret to just //@ needs-asm-ret
The `needs-asm-mnemonic` directive was very general, but in practice was only
being used for `ret`. There are very few other mnemonics that it could
plausibly be useful for (e.g. `nop`), because any instruction that requires
arguments is probably going to be non-portable.

This PR replaces `needs-asm-mnemonic` with a simpler `needs-asm-ret` directive
that uses the same machinery as other simple needs directives.

If we happend to need more mnemonics in the future, we can just add more simple
directives as appropriate (e.g. `needs-asm-nop`).
2026-05-25 17:15:32 +10:00
qaijuang
22abceee05 codegen: re-enable FileCheck for scalable-vector tuple intrinsics 2026-05-24 09:24:32 -04:00
bors
1d59f669f9 Auto merge of #156849 - saethlin:test-call-site-inline-attributes, r=dianqk
Re-add call site inlining attributes

It is very odd that we are blindly setting the call site attributes to the same as the definition, because I think the point of the call site attributes is to differentiate between calls. Probably worth looking into later, but for now I think we should just be undoing the change we made by mistake.

This fixes the accidental regression from https://github.com/rust-lang/rust/pull/156242
2026-05-24 13:02:42 +00:00
Ben Kimock
54569c6fc7 Make hint::cold_path #[cold] so that it works even if the MIR inliner can't inline it 2026-05-24 00:47:09 -04:00
Ben Kimock
adbf6f56dc Re-add call site inlining attributes 2026-05-23 16:49:04 -04:00
Scott McMurray
d3d3485dd4 Let intrinsics use the SSA operand path 2026-05-22 22:02:06 -07:00
Scott McMurray
60889bd9c2 Add some basic tests for {size,align}_of_val 2026-05-21 22:18:21 -07: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
311605c713 Rollup merge of #156462 - TimNN:flit, r=nikic
LLVM 23: Accept float (instead of hex) literals in codegen tests

https://github.com/llvm/llvm-project/pull/190649 changes how float constants are printed in LLVM IR.

@rustbot label llvm-main
2026-05-11 23:03:09 +02:00
Jonathan Brouwer
647cf45d72 Rollup merge of #156461 - TimNN:retty, r=nikic
LLVM 23: Specify `returnaddress` intrinsic return type

https://github.com/llvm/llvm-project/pull/188464 made the return type of the intrinsic generic to support different pointer address spaces.

@rustbot label llvm-main
2026-05-11 23:03:09 +02:00
Jonathan Brouwer
aeffd1585a Rollup merge of #155184 - scottmcm:intercept-array-drop-shim, r=WaffleLapkin
Have arrays' `drop_glue` just unsize and call the slice version

It's silly to emit two loops (because of the drop ladder -- just one in panic=abort) for every array length that's dropped when we can just polymorphize to the slice version.

Built atop rust-lang/rust#154327 to avoid conflicts later, so draft for now.

r? @WaffleLapkin
2026-05-11 23:03:06 +02:00
Ralf Jung
a36a97fd9b mark the 'import linkage' statics as unnamed_addr 2026-05-11 21:19:05 +02:00
Tim Neumann
8bd0b7a7a2 LLVM 23: Specify returnaddress intrinsic return type 2026-05-11 18:33:11 +02:00
Tim Neumann
fdcbe90f3d LLVM 23: Accept float (instead of hex) literals in codegen tests 2026-05-11 17:42:43 +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
Matthias Krüger
dd0746b15f Rollup merge of #155188 - DaniPopes:144329-test, r=Mark-Simulacrum
Add regression test for issue 144329

Closes https://github.com/rust-lang/rust/issues/144329.
2026-05-10 03:17:01 +02:00
Scott McMurray
05f52c7a99 Have arrays' drop_glue just unsize and call the slice version 2026-05-09 01:01:03 -07:00