Commit Graph

390 Commits

Author SHA1 Message Date
Jonathan Brouwer 2f1603077b Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009
debuginfo: emit DW_TAG_call_site entries

Set `FlagAllCallsDescribed` on function definition DIEs so LLVM emits DW_TAG_call_site entries, letting debuggers and analysis tools track tail calls.
2026-03-25 19:52:50 +01:00
Jonathan Brouwer 0cd8de3843 Rollup merge of #153049 - Darksonn:kasan-sw-tags, r=fmease
Add `-Zsanitize=kernel-hwaddress`

The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS`  that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust.

One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable.

Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it.

MCP: https://github.com/rust-lang/compiler-team/issues/975
Tracking issue: https://github.com/rust-lang/rust/issues/154171

cc @rcvalle @maurer @ojeda
2026-03-25 19:52:49 +01:00
Jonathan Brouwer 61b4c77781 Rollup merge of #154191 - pitaj:fix-154124, r=tgross35
refactor RangeFromIter overflow-checks impl

Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded

Fixes rust-lang/rust#154124

r? @tgross35
2026-03-23 12:00:59 +01:00
Jonathan Brouwer 8b69918e72 Rollup merge of #153069 - blueshift-gg:BPF_unaligned, r=chenyukang
[BPF] add target feature allows-misaligned-mem-access

This PR adds the allows-misaligned-mem-access target feature to the BPF target. The feature can enable misaligned memory access support in the LLVM backend, aligning Rust’s BPF target behavior with the corresponding LLVM update introduced in [llvm/llvm-project#167013](https://github.com/llvm/llvm-project/pull/167013) (included in LLVM 22).
2026-03-23 12:00:58 +01:00
Peter Jaszkowiak 8befc9d082 refactor RangeFromIter overflow-checks impl
Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded
2026-03-22 13:31:50 -06:00
Scott Young 9677d7a587 debuginfo: emit DW_TAG_call_site entries 2026-03-22 08:42:21 -04:00
Alice Ryhl c679e3daf2 Simplify tests and fix test tidy issue 2026-03-17 20:24:05 +00:00
Alice Ryhl e41bbfaaa6 Explain why __hwasan_tls is present in LLVM codegen 2026-03-17 20:24:05 +00:00
Alice Ryhl a197752e88 Add kernel-hwaddress sanitizer
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2026-03-17 20:23:59 +00:00
Augie Fackler b7c226c0b0 tests: accept new GEP source element type 2026-03-13 10:17:20 -04:00
Josh Stone 52dfa94cdc Update the minimum external LLVM to 21 2026-03-12 16:45:42 -07:00
Urhengulas 01e3d8549c Include optional dso_local marker for functions in enum-[match,transparent-extract].rs 2026-03-12 14:23:26 +01:00
Jonathan Brouwer 662798eb63 Rollup merge of #153305 - TimNN:bundle-assert, r=Mark-Simulacrum
Adapt codegen test to accept operand bundles

The updated test current fails when rustc is built with HEAD LLVM: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/44013/steps/canvas?sid=019cafec-3cca-44b2-aa9f-b41c0a940e8b

Likely as a result of https://github.com/llvm/llvm-project/pull/169923

Since the new codegen merges two lines into one, I couldn't figure out a way to make the test work on both LLVM versions without introducing revisions. (Though I could instead make the test run on only LLVM 23+).

@rustbot label llvm-main
2026-03-09 11:49:24 +01:00
Jonathan Brouwer 9c09ff3dcd Rollup merge of #139692 - spastorino:do-not-rustfmt-ignore, r=Mark-Simulacrum
Rustfmt now support use closures

This should be merged when https://github.com/rust-lang/rustfmt/pull/6532 is used by CI's rustfmt.
2026-03-09 11:49:23 +01:00
Jonathan Brouwer 2f5d672f46 Rollup merge of #153290 - Gelbpunkt:iter-repeat-n-trivial-drop-lower-bound-hermit, r=Mark-Simulacrum
tests: codegen-llvm: iter-repeat-n-trivial-drop: Allow non-zero lower bound to __rust_alloc size

LLVM emits a lower bound of 8 for the size parameter to `__rust_alloc` when targeting `x86_64-unknown-hermit`. Since that is also completely valid, relax the lower bound check.

I'm not really sure why LLVM is able to infer this - with the same setup targeting `x86_64-unknown-linux-gnu` I also see the lower bound of 0. Not that it's wrong, but I'd be curious to know which codegen options play into this.
2026-03-09 11:49:22 +01:00
Jonathan Brouwer a5bd6be835 Rollup merge of #152847 - Jamesbarford:chore/get_unchecked-inline-test, r=Mark-Simulacrum
Test for armv7 `get_unchecked(...)` inlining

Added test for `get_unchecked(...)` to be inlined on armv7.

closes https://github.com/rust-lang/rust/issues/131745
2026-03-09 11:49:21 +01:00
James Barford-Evans 00980f438e Test for armv7 get_unchecked(...) inlining 2026-03-09 09:18:23 +00:00
Jonathan Brouwer 83e6dbf9e1 Rollup merge of #151900 - tgross35:num-internal-imp, r=Mark-Simulacrum
num: Separate public API from internal implementations

Currently we have a single `core::num` module that contains both thin wrapper API and higher-complexity numeric routines. Restructure this by moving implementation details to a new `imp` module.

This results in a more clean separation of what is actually user-facing compared to items that have a stability attribute because they are public for testing.

The first commit does the actual change then the second moves a portion back.
2026-03-08 22:51:52 +01:00
Santiago Pastorino 85c4af74fa Rustfmt now support use closures on edition 2018 2026-03-08 10:22:26 -03:00
Josh Stone eb093cfd5d Reformat with the new stage0 2026-03-07 10:42:02 -08:00
bors 64b72a1fa5 Auto merge of #150447 - WaffleLapkin:maybe-dangling-semantics, r=RalfJung
Implement `MaybeDangling` compiler support



Tracking issue: https://github.com/rust-lang/rust/issues/118166



cc @RalfJung
2026-03-05 12:21:27 +00:00
Waffle Lapkin d6ca5c3dc0 strip readonly/captures from MaybeDangling<&T> 2026-03-05 11:53:38 +01:00
Waffle Lapkin 8aafa53504 add semantics to MaybeDangling 2026-03-05 11:53:38 +01:00
Waffle Lapkin 2ce2e0433e add a codegen-llvm test for ManuallyDrop 2026-03-05 11:53:38 +01:00
Waffle Lapkin 11bcf3759e make PointeeInfo::align non-optional
Instead of defaulting to `None` it now defaults to `Align::ONE` i.e.
no alignment restriction. Codegen test changes are due to us now skipping
`align 1` annotations (they are useless; not skipping them makes all the
raw pointers gain an `align 1` annotation which doesn't seem any good)
2026-03-05 11:53:38 +01:00
Jonathan Brouwer 7595e5b80d Rollup merge of #152283 - Sa4dUs:offload-handle-alloca, r=ZuseZ4
Properly pass offload sizes to kernel args

This PRs prevents offload from creating an unnecessary alloca when all the arg sizes are static.
I'll implement the first dynamic-size data type in a follow up PR (slice support).

r? @ZuseZ4
2026-03-05 06:31:37 +01:00
Matthias Krüger e42a3baba3 Rollup merge of #153324 - ZuseZ4:fix-ad-impl-parsing, r=oli-obk
fix autodiff parsing for non-trait impl

fixes: https://github.com/rust-lang/rust/issues/153322

@Sa4dUs Looks like we missed a case.
But also, going through the code, line 455 seems suspicious to me:
`Annotatable::AssocItem(d_fn, Impl { of_trait: false })`
Are we sure that this should always be an Impl, and never an impl of a trait?

r? @oli-obk
2026-03-04 09:49:03 +01:00
Jonathan Brouwer 0ce5963923 Rollup merge of #153285 - DeepeshWR:codegen-llvm-sqrt-call-1.94, r=folkertdev
Update call-llvm-intrinsics test for Rust 1.94.0 IR

Rust 1.94 now passes constants directly to llvm.sqrt.f32 instead of
storing/loading via the stack.

- Updated the FileCheck pattern to match the new IR:
    // CHECK: call float @llvm.sqrt.f32(float 4.000000e+00)
  The test intent is unchanged: it still ensures the intrinsic is
  emitted as a 'call' (not 'invoke').

- Removed unnecessary local variables and Drop usage to work in
  `#![no_core]` mode with minicore.

- Added required crate attributes:
    #![feature(no_core, lang_items)]
    #![no_std]
    #![no_core]

- Replaced `//@ only-riscv64` (host-based execution) with explicit
  revisions for:
      riscv32gc-unknown-linux-gnu
      riscv64gc-unknown-linux-gnu
  This ensures deterministic multi-target coverage in CI without
  relying on the host architecture.

- Added `//@ needs-llvm-components: riscv` and
  `//@ min-llvm-version: 21` for CI compatibility.

Fixes rust-lang/rust#153271
2026-03-03 13:08:45 +01:00
Marcelo Domínguez abb86d6df4 Avoid alloca for fully static sizes 2026-03-03 11:52:01 +01:00
Manuel Drehwald 52e0f3f5dc fix autodiff parsing for non-trait impl 2026-03-02 23:30:45 -05:00
Deepesh Varatharajan 1d678f6b08 Update call-llvm-intrinsics test for Rust 1.94.0 IR and multi-target CI
Rust 1.94 now passes constants directly to llvm.sqrt.f32 instead of
storing/loading via the stack.

- Updated the FileCheck pattern to match the new IR:
    // CHECK: call float @llvm.sqrt.f32(float 4.000000e+00)
  The test intent is unchanged: it still ensures the intrinsic is
  emitted as a 'call' (not 'invoke').

- Removed unnecessary local variables and Drop usage to work in
  `#![no_core]` mode with minicore.

- Added required crate attributes:
    #![feature(no_core, lang_items)]
    #![no_std]
    #![no_core]

- Replaced `//@ only-riscv64` (host-based execution) with explicit
  revisions for:
      riscv32gc-unknown-linux-gnu
      riscv64gc-unknown-linux-gnu
  This ensures deterministic multi-target coverage in CI without
  relying on the host architecture.

- Added `//@ needs-llvm-components: riscv` and
  `//@ min-llvm-version: 21` for CI compatibility.

Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
2026-03-02 18:50:12 -08:00
Tim Neumann 13ddff53be Adapt codegen test to accept operand bundles 2026-03-02 21:06:11 +01:00
Jonathan Brouwer bcfe737e50 Rollup merge of #153292 - Gelbpunkt:vec-calloc-uwtables-optional, r=jieyouxu
tests: codegen-llvm: vec-calloc: do not require the uwtable attribute

The `uwtable` attribute does not get emitted on targets that don't have unwinding tables, such as `x86_64-unknown-hermit`.
2026-03-02 20:10:36 +01:00
Jonathan Brouwer 1654b17cd8 Rollup merge of #151780 - rwardd:ryan/fix-option-permutations, r=nikic
Updated slice tests to pass for big endian hosts for `multiple-option-or-permutations.rs`

It was discovered that the FileCheck tests when performing an `Option::or` operation on a slice was failing when tested on a big endian host.

The compiler explorer link is here outlining the codegen output differences - https://rust.godbolt.org/z/qdE7d3G4f

This MR relaxes the constraints for the `*slice_u8` variants of the test (by changing `CHECK-NEXT` to `CHECK-DAG`), whilst still maintaining the check for the necessary `or` logic.

Huge thanks to @Gelbpunkt for identifying this issue! It has been confirmed that this fix passes on a big endian target now as well.

Closes rust-lang/rust#151718
2026-03-02 20:10:33 +01:00
Aelin Reidel b4d36db16e tests: codegen-llvm: vec-calloc: do not require the uwtable attribute
The uwtable attribute does not get emitted on targets that don't have
unwinding tables, such as x86_64-unknown-hermit.
2026-03-02 15:31:59 +01:00
Aelin Reidel affe60917c tests: codegen-llvm: iter-repeat-n-trivial-drop: Allow non-zero lower bound to __rust_alloc size
LLVM emits a lower bound of 8 for the size parameter to __rust_alloc
when targeting x86_64-unknown-hermit. Since that is also completely
valid, relax the lower bound check.
2026-03-02 15:18:55 +01:00
bors c2c6f74fd2 Auto merge of #152864 - TKanX:bugfix/123183-array-cast-abi-noundef, r=RalfJung
perf(codegen): Restore `noundef` On `PassMode::Cast` Args In Rust ABI



### Summary:

#### Problem:

Small aggregate arguments passed via `PassMode::Cast` in the Rust ABI (e.g. `[u32; 2]` cast to `i64`) are missing `noundef` in the emitted LLVM IR, even when the type contains no uninit bytes:

```rust
#[no_mangle]
pub fn f(v: [u32; 2]) -> u32 { v[0] }
```

```llvm
; expected: define i32 @f(i64 noundef %0)
; actual:   define i32 @f(i64 %0)           ← noundef missing
```

This blocks LLVM from applying optimizations that require value-defined semantics on function arguments.

#### Root Cause:

`adjust_for_rust_abi` calls `arg.cast_to(Reg::Integer)`, which internally creates a `CastTarget` with `ArgAttributes::new()` — always empty. Any validity attribute that was present before the cast is silently dropped.

This affects all `PassMode::Cast` arguments and return values in the Rust ABI: plain arrays, newtype wrappers, and any `BackendRepr::Memory` type small enough to fit in a register.

A prior attempt (rust-lang/rust#127210) used `Ty`/`repr` attributes to detect padding.

#### Solution:

After `adjust_for_rust_abi`, iterate all `PassMode::Cast` args and the return value. For each, call `layout_is_noundef` on the original layout; if it returns `true`, set `NoUndef` on the `CastTarget`'s `attrs`.

`layout_is_noundef` uses only the computed layout — `BackendRepr`, `FieldsShape`, `Variants`, `Scalar::is_uninit_valid()` — and never touches `Ty` or repr attributes. **Anything it cannot prove returns `false`.**

Covered cases:
- `Scalar` / `ScalarPair` (both halves initialized, fields contiguous)
- `FieldsShape::Array` (element type recursively uninit-free)
- `FieldsShape::Arbitrary` with `Variants::Single` (fields cover `0..size` with no gaps, each recursively uninit-free) — handles newtype wrappers, multi-field structs, single-variant enums, `repr(transparent)`, `repr(C)` wrappers

Conservatively excluded with FIXMEs:
- Multi-variant enums (per-variant padding analysis needed)
- Foreign-ABI casts (cast target may exceed layout size, needs a size guard)

### Changes:

- `compiler/rustc_ty_utils/src/abi.rs`: add restoration loop after `adjust_for_rust_abi`; add `layout_is_noundef` and `fields_cover_layout`.
- `tests/codegen-llvm/abi-noundef-cast.rs`: new FileCheck test covering arrays, newtype wrappers (`repr(Rust)`, `repr(transparent)`, `repr(C)`), multi-field structs, single-variant enums, return values, and negative cases (`MaybeUninit`, struct with trailing padding).
- `tests/codegen-llvm/debuginfo-dse.rs`: update one CHECK pattern — `Aggregate_4xi8` (`struct { i8, i8, i8, i8 }`) now correctly gets `noundef`.

Fixes rust-lang/rust#123183.

r? @RalfJung
2026-03-01 01:50:36 +00:00
bors 67aec36df7 Auto merge of #153183 - JonathanBrouwer:rollup-APFHc2s, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#151143 (explicit tail calls: support indirect arguments)
 - rust-lang/rust#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`)
 - rust-lang/rust#153175 (Clarify a confusing green-path function)
 - rust-lang/rust#153179 (Force a CI LLVM stamp bump)
 - rust-lang/rust#150828 (Improved security section in rustdoc for `current_exe`)
 - rust-lang/rust#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate)
 - rust-lang/rust#152674 (rustc_public: remove the `CrateDefItems` trait)
 - rust-lang/rust#153073 (Fix mem::conjure_zst panic message to use any::type_name instead)
 - rust-lang/rust#153117 (Remove mutation from macro path URL construction)
 - rust-lang/rust#153128 (Recover feature lang_items for emscripten)
 - rust-lang/rust#153138 (Print path root when printing path)
 - rust-lang/rust#153159 (Work around a false `err.emit();` type error in rust-analyzer)
2026-02-27 22:04:20 +00:00
Tony Kan 97bd985467 fix(abi): Restore noundef on PassMode::Cast args in Rust ABI
`adjust_for_rust_abi` was casting small aggregates to an integer register
without propagating `noundef`, causing a performance regression (#123183)
— LLVM could no longer assume the bits were fully defined.

Add `layout_is_noundef` (conservative) + `fields_are_noundef` helper,
then use `cast_to_with_attrs` to forward `NoUndef` when proven:

  Scalar     → `!is_uninit_valid()`
  ScalarPair → both scalars valid + `s1.size + s2.size == layout.size`
               (size equality rejects layouts with inter-scalar padding)
  Array      → recurse into element; empty arrays unconditionally noundef
  Arbitrary  → `Variants::Single` required; walk fields in offset order —
               any gap, non-noundef field, or trailing pad returns false
  Union / Primitive / Simd → false (conservative)

Bless `pass-indirectly-attr.stderr` and `debuginfo-dse.rs` for the new
attribute on Cast args. Add `tests/codegen-llvm/abi-noundef-cast.rs`
covering positive Cast cases (arrays, plain structs, single-variant enum)
and negative Cast cases (MaybeUninit, multi-variant enum, field/pair gap,
trailing padding).

Fixes #123183.

Co-authored-by: Ralf Jung <post@ralfj.de>
2026-02-27 12:08:59 -08:00
bors 3a70d0349f Auto merge of #152702 - oli-obk:nonnulltransmute, r=scottmcm
Prepare NonNull for pattern types



Pull out the changes that affect some tests, but do not require pattern types.

See https://github.com/rust-lang/rust/pull/136006#discussion_r2806740338 for what triggered this PR

r? @scottmcm
2026-02-27 13:04:46 +00:00
Folkert de Vries e6cf5a22e7 test u128 passing on linux and windows 2026-02-27 10:51:55 +01:00
bors 6a979b3e32 Auto merge of #153108 - alexcrichton:revert, r=joboet
Revert "Simplify internals of `{Rc,Arc}::default`"

This reverts rust-lang/rust#152591 following a [perf run being done](https://github.com/rust-lang/rust/pull/152591#issuecomment-3960081137). I'm not really positioned at this time to dive in further and understand the performance regressions, so I'll back away from `Rc`/`Arc` and leave them as-is.
2026-02-26 19:51:40 +00:00
Jacob Pratt cb78bc4dd4 Rollup merge of #151771 - hoodmane:wasm-double-panic, r=bjorn3
Fix: On wasm targets, call `panic_in_cleanup` if panic occurs in cleanup

Previously this was not correctly implemented. Each funclet may need its own terminate block, so this changes the `terminate_block` into a `terminate_blocks` `IndexVec` which can have a terminate_block for each funclet. We key on the first basic block of the funclet -- in particular, this is the start block for the old case of the top level terminate function.

I also fixed the `terminate` handler to not be invoked when a foreign exception is raised, mimicking the behavior from msvc. On wasm, in order to avoid generating a `catch_all` we need to call `llvm.wasm.get.exception` and `llvm.wasm.get.ehselector`.
2026-02-25 21:42:53 -05:00
Alex Crichton 57d20c1d14 Revert "Simplify internals of {Rc,Arc}::default"
This reverts commit ce4c17f615.
2026-02-25 13:09:14 -08:00
Claire Fan f62b2f3b4d [BPF] add target feature allows-misaligned-mem-access 2026-02-25 21:31:51 +08:00
Hood Chatham acbfd79acf Fix: On wasm targets, call panic_in_cleanup if panic occurs in cleanup
Previously this was not correctly implemented. Each funclet may need its own terminate
block, so this changes the `terminate_block` into a `terminate_blocks` `IndexVec` which
can have a terminate_block for each funclet. We key on the first basic block of the
funclet -- in particular, this is the start block for the old case of the top level
terminate function.

Rather than using a catchswitch/catchpad pair, I used a cleanuppad. The reason for the
pair is to avoid catching foreign exceptions on MSVC. On wasm, it seems that the
catchswitch/catchpad pair is optimized back into a single cleanuppad and a catch_all
instruction is emitted which will catch foreign exceptions. Because the new logic is
only used on wasm, it seemed better to take the simpler approach seeing as they do the
same thing.
2026-02-24 17:47:27 +01:00
Oli Scherer 241cd7eeed Prepare NonNull for pattern types 2026-02-24 08:33:15 +00:00
Stuart Cook 62bc8727c3 Rollup merge of #152970 - RalfJung:unpin-noalias-tests, r=Mark-Simulacrum
extend unpin noalias tests to cover mutable references

https://github.com/rust-lang/rust/pull/152946 made a change to the logic for this attribute that the test should have flagged as problematic -- but the test only checked `Box`, not `&mut`, and those have independent code paths. So extend the test to also cover `&mut`.

@b-naber would be nice if you could confirm that the added tests do fail with your PR.
2026-02-23 13:31:58 +11:00
Ralf Jung b56949bddf extend unpin noalias tests to cover mutable references 2026-02-22 15:24:20 +01:00
Jonathan Brouwer 00d849a1b9 Rollup merge of #152591 - alexcrichton:simplify-rc-arc-default, r=joboet
Simplify internals of `{Rc,Arc}::default`

This commit simplifies the internal implementation of `Default` for these two pointer types to have the same performance characteristics as before (a side effect of changes in rust-lang/rust#131460) while avoid use of internal private APIs of Rc/Arc. To preserve the same codegen as before some non-generic functions needed to be tagged as `#[inline]` as well, but otherwise the same IR is produced before/after this change.

The motivation of this commit is I was studying up on the state of initialization of `Arc` and `Rc` and figured it'd be nicer to reduce the use of internal APIs and instead use public stable APIs where possible, even in the implementation itself.
2026-02-22 11:31:13 +01:00