2928 Commits

Author SHA1 Message Date
Jacob Pratt
03fbcdb8ee
Rollup merge of #145705 - folkertdev:prefetch-remove-as-cast, r=RalfJung
remove an `as` cast in prefetch codegen

r? `@RalfJung`
2025-08-21 17:57:58 -04:00
Folkert de Vries
b32f4d5792
remove an as cast in prefetch codegen 2025-08-21 11:28:10 +02:00
Jacob Pratt
537d5f40a6
Rollup merge of #145297 - adwinwhite:recursive-debuginfo, r=wesleywiser
fix(debuginfo): handle false positives in overflow check

Fixes rust-lang/rust#144636.

Duplicate wrappers and normal recursive types can lead to false positives.
```rust
struct Recursive {
	a: Box<Box<Recursive>>,
}
```
The ADT stack can be:
- `Box<Recursive>`
- `Recursive`
- `Box<Box<Recursive>>` (`Box` now detected as expanding)

We can filter them out by tracing the generic arg back through the stack, as true expanding recursive types must have their expanding arg used as generic arg throughout.

r? ````@wesleywiser````
2025-08-21 01:12:16 -04:00
bors
125ff8a788 Auto merge of #145259 - nikic:read-only-capture, r=wesleywiser
Tell LLVM about read-only captures

`&Freeze` parameters are not only `readonly` within the function, but any captures of the pointer can also only be used for reads. This can now be encoded using the `captures(address, read_provenance)` attribute.
2025-08-20 23:41:41 +00:00
bors
040a98af70 Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic
Pass `alloc-variant-zeroed` to LLVM

Makes use of https://github.com/llvm/llvm-project/pull/138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires https://github.com/llvm/llvm-project/pull/149336 to work.~~

Closes rust-lang/rust#104847
2025-08-20 17:16:34 +00:00
Nikita Popov
d71ed8d19b Tell LLVM about read-only captures
`&Freeze` parameters are not only `readonly` within the function,
but any captures of the pointer can also only be used for reads.
This can now be encoded using the `captures(address, read_provenance)`
attribute.
2025-08-20 19:08:16 +02:00
clubby789
8ea3b09381 Pass alloc-variant-zeroed to LLVM 2025-08-20 17:08:46 +01:00
Jacob Pratt
816f098464
Rollup merge of #145626 - folkertdev:prefetch-fallback, r=Amanieu
add a fallback implementation for the `prefetch_*` intrinsics

related ACP: https://github.com/rust-lang/libs-team/issues/638

The fallback is to just ignore the arguments. That is a valid implementation because this intrinsic is just a hint.

I also added the `miri::intrinsic_fallback_is_spec` annotation, so that miri now supports these operations. A prefetch intrinsic call is valid on any pointer. (specifically LLVM guarantees this https://llvm.org/docs/LangRef.html#llvm-prefetch-intrinsic)

Next, I made the `LOCALITY` argument a const generic. That argument must be const (otherwise LLVM crashes), but that was not reflected in the type.

Finally, with these changes, the intrinsic can be safe and `const` (a prefetch at const evaluation time is just a no-op).

cc `@Amanieu`
r? `@RalfJung`
2025-08-20 00:46:02 -04:00
Folkert de Vries
d25910eaeb
make prefetch intrinsics safe 2025-08-20 00:35:42 +02:00
bors
05f5a58e84 Auto merge of #145600 - jieyouxu:rollup-jw0bpnt, r=jieyouxu
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#145338 (actually provide the correct args to coroutine witnesses)
 - rust-lang/rust#145429 (Couple of codegen_fn_attrs improvements)
 - rust-lang/rust#145452 (Do not strip binaries in bootstrap everytime if they are unchanged)
 - rust-lang/rust#145464 (Stabilize `const_pathbuf_osstring_new` feature)
 - rust-lang/rust#145474 (Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups)
 - rust-lang/rust#145486 (Fix `unicode_data.rs` mention message)
 - rust-lang/rust#145490 (Trace some basic I/O operations in bootstrap)
 - rust-lang/rust#145493 (remove `should_render` in `PrintAttribute` derive)
 - rust-lang/rust#145500 (Port must_use to the new target checking)
 - rust-lang/rust#145505 (Simplify span caches)
 - rust-lang/rust#145510 (Visit and print async_fut local for async drop.)
 - rust-lang/rust#145511 (Rust build fails on OpenBSD after using file_lock feature)
 - rust-lang/rust#145532 (resolve: debug for block module)
 - rust-lang/rust#145533 (Reorder `lto` options from most to least optimizing)
 - rust-lang/rust#145537 (Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-19 19:26:10 +00:00
许杰友 Jieyou Xu (Joe)
62227334ae
Rollup merge of #145429 - bjorn3:codegen_fn_attrs_improvements, r=jdonszelmann
Couple of codegen_fn_attrs improvements

As noted in https://github.com/rust-lang/rust/pull/144678#discussion_r2245060329 here is no need to keep link_name and export_name separate, which the third commit fixes by merging them. The second commit removes some dead code and the first commit merges two ifs with equivalent conditions. The last commit is an unrelated change which removes an unused `feature(autodiff)`.
2025-08-19 19:45:31 +08:00
许杰友 Jieyou Xu (Joe)
bdd3bc82c8
Rollup merge of #145099 - heiher:loong-32s, r=folkertdev
rustc_target: Add the `32s` target feature for LoongArch

LLVM: https://github.com/llvm/llvm-project/pull/139695
2025-08-19 19:42:08 +08:00
许杰友 Jieyou Xu (Joe)
df01a87de2
Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco
Add `-Zindirect-branch-cs-prefix`

Cc: ``@azhogin`` ``@Darksonn``

This goes on top of https://github.com/rust-lang/rust/pull/135927, i.e. please skip the first commit here. Please feel free to inherit it there.

In fact, I am not sure if there is any use case for the flag without `-Zretpoline*`. GCC and Clang allow it, though.

There is a `FIXME` for two `ignore`s in the test that I took from another test I did in the past -- they may be needed or not here since I didn't run the full CI. Either way, it is not critical.

Tracking issue: https://github.com/rust-lang/rust/issues/116852.
MCP: https://github.com/rust-lang/compiler-team/issues/868.
2025-08-19 19:42:01 +08:00
Stuart Cook
8748d8e7d5
Rollup merge of #145484 - Zalathar:archive-builder, r=bjorn3
Remove `LlvmArchiveBuilder` and supporting code/bindings

Switching over to the newer Rust-based `ArArchiveBuilder` happened in rust-lang/rust#128936, a year ago.

Per the comment in `new_archive_builder`, that seems like enough time to justify removing the older, unused `LlvmArchiveBuilder` implementation and its associated bindings.

Fixes rust-lang/rust#128955.
2025-08-19 14:18:25 +10:00
Stuart Cook
8945924d77
Rollup merge of #145432 - Zalathar:target-machine, r=wesleywiser
cg_llvm: Small cleanups to `owned_target_machine`

This PR contains a few tiny cleanups to the `owned_target_machine` code.

Each individual commit should be fairly straightforward.
2025-08-19 14:18:25 +10:00
Stuart Cook
aa2dcbe583
Rollup merge of #145420 - Zalathar:llvm-c, r=WaffleLapkin
cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind`

This PR replaces two existing `LLVMRust` bindings with equivalent calls to the LLVM-C API.

For `LLVMGetTypeKind`, we avoid the UB hazard by declaring the foreign function to return `RawEnum<TypeKind>` (which is a wrapper around `u32`), and then perform checked conversion from `u32` to `TypeKind`.
2025-08-18 15:31:12 +10:00
Stuart Cook
1e454c64b2
Rollup merge of #145309 - winstonallo:issue-145271-fix, r=tgross35
Fix `-Zregparm` for LLVM builtins

This fixes the issue where `-Zregparm=N` was not working correctly when calling LLVM intrinsics

By default on `x86-32`, arguments are passed on the stack. The `-Zregparm=N` flag allows the first `N` arguments to be passed in registers instead.

When calling intrinsics like `memset`, LLVM still passes parameters on the stack, which prevents optimizations like tail calls.

As proposed by ````@tgross35,```` I fixed this by setting the `NumRegisterParameters` LLVM module flag to `N` when the `-Zregparm=N` is set.

```rust
// compiler/rust_codegen_llvm/src/context.rs#375-382
if let Some(regparm_count) = sess.opts.unstable_opts.regparm {
    llvm::add_module_flag_u32(
        llmod,
        llvm::ModuleFlagMergeBehavior::Error,
        "NumRegisterParameters",
        regparm_count,
    );
}
```
[Here](https://rust.godbolt.org/z/YMezreo48) is a before/after compiler explorer.

Here is the final result for the code snippet in the original issue:
```asm
entrypoint:
        push    esi
        mov     esi, eax
        mov     eax, ecx
        mov     ecx, esi
        pop     esi
        jmp     memset   ; Tail call parameters in registers
```

Fixes: https://github.com/rust-lang/rust/issues/145271
2025-08-18 15:31:11 +10:00
Alice Ryhl
1cd7080c3a Add -Zindirect-branch-cs-prefix (from draft PR) 2025-08-17 16:50:23 +02:00
Zalathar
cf8ec6798f Remove LlvmArchiveBuilder and supporting code/bindings 2025-08-16 16:38:12 +10:00
Zalathar
9e7d066928 Simplify the args_cstr_buff assertion 2025-08-15 20:24:13 +10:00
Zalathar
61932e1222 Avoid an unnecessary intermediate &mut reference
The `NonNull::as_mut` method returns a mut *reference*, rather than the mut
*pointer* that is intended here.
2025-08-15 20:24:13 +10:00
Zalathar
44f5ec7d56 Avoid an explicit cast from *const c_uchar to *const c_char
As noted in the `ffi` module docs, passing pointer/length byte strings from
Rust to C++ is easier if we declare them as `*const c_uchar` on the Rust side,
but `const char *` (possibly signed) on the C++ side. This is allowed because
both pointer types are ABI-compatible, regardless of char signedness.
2025-08-15 20:24:13 +10:00
Zalathar
8d0a04966c Declare module rustc_codegen_llvm::back in the normal way
Declaring these submodules directly in `lib.rs` was needlessly confusing.
2025-08-15 20:24:13 +10:00
bjorn3
460519a7f5 Merge link_name and export_name 2025-08-15 10:04:04 +00:00
Zalathar
e193b5342b Use LLVMGetTypeKind 2025-08-15 19:35:35 +10:00
Stuart Cook
201e6324a7
Rollup merge of #145275 - StackOverflowExcept1on:fix-wasm32v1-none, r=alexcrichton
fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute

Resolves rust-lang/rust#140174

r? ```@alexcrichton```

try-job: `test-various*`
2025-08-15 16:16:38 +10:00
Stuart Cook
0166de2f87
Rollup merge of #145120 - maurer:llvm-time, r=nikic
llvm: Accept new LLVM lifetime format

In llvm/llvm-project#150248 LLVM removed the size parameter from the lifetime format. Tolerate not having that size parameter.
2025-08-15 16:16:37 +10:00
Stuart Cook
60cb5502c1
Rollup merge of #145004 - bjorn3:remove_unused_fields, r=WaffleLapkin
Couple of minor cleanups
2025-08-15 16:16:33 +10:00
Zalathar
c64c6d85e1 Use LLVMSetTailCallKind 2025-08-15 13:57:37 +10:00
Marcelo Domínguez
e1d79b9aad Remove lto inline logic 2025-08-14 16:30:16 +00:00
Marcelo Domínguez
c9c1c17128 Remove inlining for autodiff handling 2025-08-14 16:30:16 +00:00
Marcelo Domínguez
250d77e5d7 Complete functionality and general cleanup 2025-08-14 16:30:15 +00:00
Marcelo Domínguez
5c631041aa Basic implementation of autodiff intrinsic 2025-08-14 16:29:58 +00:00
Guillaume Gomez
44d3217c20
Rollup merge of #145323 - scrabsha:push-pqwvmznzzmpr, r=jdonszelmann
Port the `#[linkage]` attribute to the new attribute system

r? `@jdonszelmann`
2025-08-14 11:39:39 +02:00
Guillaume Gomez
ad21c6d898
Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkov
Reduce some queries around associated items
2025-08-14 11:39:38 +02:00
Sasha Pourcelot
d435197afc Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
StackOverflowExcept1on
f978932903 fix(compiler/rustc_codegen_llvm): apply target-cpu attribute 2025-08-13 17:49:06 +00:00
Guillaume Gomez
a6146fddcf
Rollup merge of #145241 - tomtor:avr-layout, r=nikic
[AVR] Changed data_layout

This change is required when

97f0ff0c80

gets included in the Rust llvm tree, because it changes the AVR data-layout
2025-08-13 18:43:02 +02:00
winstonallo
04ff1444bb
Set NumRegisterParameters LLVM module flag to N when -Zregparm=N is
set

* Enforce the `-Zregparm=N` flag by setting the NumRegisterParameters
LLVM module flag * Add assembly tests verifying that the parameters are
passed in registers for reparm values 1, 2, and 3, for both LLVM
intrinsics and non-builtin functions * Add c_void type to minicore
2025-08-13 17:37:30 +02:00
Cameron Steffen
d4eb0947f1 Cleanup assoc parent utils 2025-08-13 09:33:09 -05:00
bors
b1b26b834d Auto merge of #145093 - nikic:dead-on-return, r=nnethercote
Set dead_on_return attribute for indirect arguments

Set the dead_on_return attribute (added in LLVM 21) for arguments that are passed indirectly, but not byval.

This indicates that the value of the argument on return does not matter, enabling additional dead store elimination.

From LangRef:

> This attribute indicates that the memory pointed to by the argument is dead upon function return, both upon normal return and if the calls unwinds, meaning that the caller will not depend on its contents. Stores that would be observable either on the return path or on the unwind path may be elided.
>
> Specifically, the behavior is as-if any memory written through the pointer during the execution of the function is overwritten with a poison value upon function return. The caller may access the memory, but any load not preceded by a store will return poison.
>
> This attribute does not imply aliasing properties. For pointer arguments that do not alias other memory locations, noalias attribute may be used in conjunction. Conversely, this attribute always implies dead_on_unwind.
>
> This attribute cannot be applied to return values.

This fixes parts of https://github.com/rust-lang/rust/issues/96497.
2025-08-13 04:18:43 +00:00
Adwin White
e13e1e4c0c fix(debuginfo): handle false positives in overflow check 2025-08-12 17:13:13 +08:00
Tom Vijlbrief
2563e4a7ff [AVR] Changed data_layout 2025-08-12 08:33:27 +02:00
Matthew Maurer
258915a555 llvm: Accept new LLVM lifetime format
LLVM removed the size parameter from the lifetime format.
Tolerate not having that size parameter.
2025-08-11 22:00:41 +00:00
Nikita Popov
ebef9d7f63 Set dead_on_return attribute for indirect arguments
Set the dead_on_return attribute (added in LLVM 21) for arguments
that are passed indirectly, but not byval.

This indicates that the value of the argument on return does not
matter, enabling additional dead store elimination.
2025-08-11 12:39:23 +02:00
WANG Rui
0246245420 rustc_target: Add the 32s target feature for LoongArch 2025-08-09 13:54:09 +08:00
Scott McMurray
8831c5b994 Stop using uadd.with.overflow 2025-08-08 21:59:28 -07:00
Trevor Gross
660bf919dc
Rollup merge of #144987 - tgross35:llvm21-f16-f128, r=nikic
Enable f16 and f128 on targets that were fixed in LLVM21

LLVM21 fixed the new float types on a number of targets:

* SystemZ gained f16 support  https://github.com/llvm/llvm-project/pull/109164
* Hexagon now uses soft f16 to avoid recursion bugs  https://github.com/llvm/llvm-project/pull/130977
* Mips now correctly handles f128 (actually since LLVM20) https://github.com/llvm/llvm-project/pull/117525
* f128 is now correctly aligned when passing the stack on x86  https://github.com/llvm/llvm-project/pull/138092

Thus, enable the types on relevant targets for LLVM > 21.0.0.

NVPTX also gained handling of f128 as a storage type, but it lacks support for basic math operations so is still disabled here.

try-job: dist-i586-gnu-i586-i686-musl
try-job: dist-i686-linux
try-job: dist-i686-msvc
try-job: dist-s390x-linux
try-job: dist-various-1
try-job: dist-various-2
try-job: dist-x86_64-linux
try-job: i686-gnu-1
try-job: i686-gnu-2
try-job: i686-msvc-1
try-job: i686-msvc-2
try-job: test-various
2025-08-08 14:22:47 -05:00
Trevor Gross
6fa6a854cd
Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikic
atomicrmw on pointers: move integer-pointer cast hacks into backend

Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere.

This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.

Cc ```@nikic``` -- this is the best we can do right now, right?
Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-08 14:22:44 -05:00
bjorn3
8f648d7185 Remove bitcode_llvm_cmdline
It used to be necessary on Apple platforms to ship with the App Store,
but XCode 15 has stopped embedding LLVM bitcode and the App Store no
longer accepts apps with bitcode embedded.
2025-08-08 11:24:28 +00:00