Commit Graph

579 Commits

Author SHA1 Message Date
Jonathan Brouwer
7fd85325c0 Rollup merge of #158697 - ferrocene:qnx-sdp-8-fixes, r=aapoalas
Fixes for QNX SDP 8

This PR contains libstd fixes so libstd can be build for QNX SDP 8.

It requires patches to libc-0.2 and cc-rs. The cc-rs patch [was merged]([rust-lang/cc-rs#1775](https://github.com/rust-lang/cc-rs/issues/1775)) already. I have a patch for libc-1.0 [here](https://github.com/rust-lang/libc/issues/5241) which will need backporting to libc-0.2 once merged.

With these in place, I was able to remotely `test tests/ui library/std library/alloc library/core` for `x86_64-pc-qnx` using a remote-test-server running on QNX SDP 8.0's QEMU BSP image. The only tests that failed were the two `tests/ui/codegen/huge-stacks.rs` tests, and I did not have enough RAM to run them.
2026-07-07 22:26:55 +02:00
Jorge Aparicio
49769afe4b QNX SDP 8 fixes.
1) setsid/setpgrp: check child's group process ID

Linux [1], FreeBSD [2] and the Open Group [3] manuals for both setsid and
setpgrp state that the calling process will be assigned a process group ID that
matches its process ID so check that's the case in the test by calling
getpgid on the child process ID.

on QNX8 (as of GA8.0.2) libc::kill(pgid) appears unable to terminate the
child process so skip that check on that target as it's behavior that
libstd provides no API for

[1]: https://man7.org/linux/man-pages/man2/setsid.2.html
[2]: https://man.freebsd.org/cgi/man.cgi?query=setsid&sektion=2
[3]: https://pubs.opengroup.org/onlinepubs/000095399/functions/setsid.html

2) fix handling of sockaddr_un.len on QNX

also extend the existing tests to exercise the getsockname(2) and
getpeername(2) paths with both named and unnamed Unix sockets

3) Additional fixes library/std after earlier PR renamed some targets

4) Replace more instances of "QNX Neutrino / QNX OS" with "QNX SDP" and fix up some documentation URLs

5) Tests ignored on target_os = "nto" should also be ignored on target_os = "qnx".

6) Simplify nto-qnx.md documentation

cc-rs now knows about QNX so the environment isn't required
2026-07-07 17:31:05 +01:00
Jacob Pratt
a321df92ed Rollup merge of #158377 - folkertdev:force-intrinsic-fallback, r=saethlin
add `-Zforce-intrinsic-fallback` flag

Add a flag that forces the use of the fallback body (if one exists), so that we can test that these fallback implementations actually work.

cc https://github.com/rust-lang/rust/pull/150946
cc [#t-compiler > testing intrinsic fallback bodies](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/testing.20intrinsic.20fallback.20bodies/with/606299558)
cc [#t-infra > CI for -Zforce-intrinsic-fallback](https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/CI.20for.20-Zforce-intrinsic-fallback/with/608129693)
2026-07-06 04:33:05 -04:00
Folkert de Vries
6810f13f1d add -Zforce-intrinsic-fallback flag 2026-07-05 15:32:49 +02:00
Jonathan Brouwer
2085491fdf Rollup merge of #156777 - sgasho:test-fix-codegen-llvm-autodiff-2, r=ZuseZ4
Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust

* Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust
* Change some llvm ir check in codegen_llvm/autodiff tests

r? @ZuseZ4
2026-07-05 14:12:03 +02:00
Jonathan Brouwer
cef63f3327 Rollup merge of #155989 - scottmcm:unsized-transmute-copy, r=Mark-Simulacrum
Update `transmute_copy` to ub_checks and `?Sized`

The `assert!` in `transmute_copy` is from rust-lang/rust#98839.  However, it was controversial at the time because it's possible to write `transmute_copy`s that were UB by the description but didn't pass the documented conditions.  It's also sub-optimal to have possible `panic`s in unsafe code where the panic can actually make things worse by dropping things in the middle of what the programmer expected to be panic-free.  Now that we have the `UbChecks` possibility, though, we can do this better: this PR makes it a *non-unwinding* panic when not meeting the documented condition when UB checks are enabled, but which very clearly emphasizes that said check isn't a documented behaviour of the function.

Also, I was staring at the signature and couldn't figure out why it needs `Src: Sized`.  Since it *always* takes a reference, there seems to be no downside to accepting `Src: ?Sized`.  That would also give it more of a reason to exist even if <https://doc.rust-lang.org/nightly/std/mem/fn.transmute_prefix.html> exists (as `transmute_prefix(x)` existing will no longer need the `transmute_copy(&ManuallyDrop::new(x))` polyfill, cc https://github.com/rust-lang/rfcs/pull/3844).  That definitely needs an FCP, though.

(The change to `assert_unsafe_precondition` here doesn't technically need libs-api assent, but I'd still like to hear your thoughts since it's different from the "promise the assert" that IIRC you were also asked to consider elsewhere.)

A partial replacement for rust-lang/rust#154665
2026-07-05 14:12:02 +02:00
sgasho
2a9e45d646 Update LLVM IR checks in codegen-llvm/autodiff tests 2026-07-03 00:44:39 +09:00
Jacob Pratt
02ee82569e Rollup merge of #158427 - scottmcm:write-unaligned-via-packed, r=aapoalas
Implement `ptr::{read,write}_unaligned` via `repr(packed)`

We already support doing unaligned reads & writes via `repr(packed)` fields, so this just uses that support from the backend rather than needing to thinks about `memcpy` and `intrinsics::forget` and such.

Turns out in codegen this ends up essentially identical because the packed type read gets `BackendRepr::Memory` and thus the read/write of the packed type *is* an `align 1` memcpy, just like the library code before this PR.  But doing this gives much simpler MIR and https://github.com/rust-lang/rust/pull/158291 will make it better than the previous version by not needing to emit the `memcpy` at all for things like `read_unaligned::<u32>`.

First commit are some tests that pass on master; Second commit changes the implementation and shows the corresponding test changes.

r? libs
2026-07-01 17:42:26 -04:00
Scott McMurray
a3a8023742 Update transmute_copy to ub_checks and ?Sized 2026-07-01 11:48:06 -07:00
bors
51657149e9 Auto merge of #158595 - JonathanBrouwer:rollup-vgnGLp0, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - rust-lang/rust#158256 (Avoid parser panics bubbling out to proc macros)
 - rust-lang/rust#158561 (Avoid building rustdoc for tests without doctests)
 - rust-lang/rust#158562 (Improve tracing of steps in bootstrap)
 - rust-lang/rust#157445 (Allow section override when using patchable-function-entries)
 - rust-lang/rust#158327 (Move attribute and keyword docs from `std` to `core`)
 - rust-lang/rust#158591 (Fix spacing issue for unused parentheses lint)
2026-06-30 08:40:27 +00:00
Jonathan Brouwer
67b5ab7707 Rollup merge of #155722 - jchlanda:jakub/pac, r=davidtwco
Introduce aarch64-unknown-linux-pauthtest target

This target enables Pointer Authentication Code (PAC) support in Rust on AArch64
ELF-based Linux systems. It uses the `aarch64-unknown-linux-pauthtest` LLVM
target and a pointer-authentication-enabled sysroot with a custom musl as a
reference libc implementation. Dynamic linking is required, with a dynamic
linker acting as the ELF interpreter that can resolve pauth relocations and
enforce pointer authentication constraints.

### Supported features include:
* authentication of signed function pointers for extern "C" calls (corresponds
  to LLVM's `-fptrauth-calls`)
* signing of return addresses before spilling to the stack and authentication
  after restoring for non-leaf functions (corresponds to `-fptrauth-returns`)
* trapping on authentication failure when the FPAC feature is not present
  (corresponds to `-fptrauth-auth-traps`)
* signing of init/fini array entries using the LLVM-defined pointer
  authentication scheme (corresponds to `-fptrauth-init-fini` and
  `-fptrauth-init-fini-address-discrimination`)
* non-ABI-affecting indirect control-flow hardening features as implemented in
  LLVM (corresponds to `-faarch64-jump-table-hardening` and
  `-fptrauth-indirect-gotos`)
* signed ELF GOT entries (gated behind `-Z ptrauth-elf-got`, off by default)

Existing compiler support, such as enabling branch authentication instructions
(i.e.: `-Z branch-protection`) provide limited functionality, mainly signing
return addresses (`pac-ret`). The new target goes further by enabling ABI-level
pointer authentication support.

This target does not define a new ABI; it builds on the existing C/C++ language
ABI with pointer authentication support added. However, different authentication
features, encoded in the signing schema, are not ABI-compatible with one
another.

### Useful links:
* Earlier PR: https://github.com/rust-lang/rust/pull/154759
* Part of: https://github.com/rust-lang/rust/issues/148640
* Project goal: https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html
* Clang pointer authentication documentation:
  https://clang.llvm.org/docs/PointerAuthentication.html
* LLVM pointer authentication documentation:
  https://llvm.org/docs/PointerAuth.html
* PAuth ABI Extension to ELF for the AArch64 architecture:
  https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst

### Tier 3 check list
> - A tier 3 target must have a designated developer or developers (the "target
>   maintainers") on record to be CCed when issues arise regarding the target.
>   (The mechanism to track and CC such developers may evolve over time.)

I pledge to do my best maintaining it.

> - Targets must use naming consistent with any existing targets; for instance, a
>   target for the same CPU or OS as an existing Rust target should use the same
>   name for that CPU or OS. Targets should normally use the same names and
>   naming conventions as used elsewhere in the broader ecosystem beyond Rust
>   (such as in other toolchains), unless they have a very good reason to
>   diverge. Changing the name of a target can be highly disruptive, especially
>   once the target reaches a higher tier, so getting the name right is important
>   even for a tier 3 target.

The name chosen for the target is `aarch64-unknown-linux-pauthtest` which
mirrors the [LLVM target naming](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/TargetParser/TripleTest.cpp#L1407).

>   - Target names should not introduce undue confusion or ambiguity unless
>     absolutely necessary to maintain ecosystem compatibility. For example, if
>     the name of the target makes people extremely likely to form incorrect
>     beliefs about what it targets, the name should be changed or augmented to
>     disambiguate it.

There should be no confusion, the name follows naming convention and is
descriptive.

>   - If possible, use only letters, numbers, dashes and underscores for the name.
>     Periods (`.`) are known to cause issues in Cargo.

Letters, numbers and dashes only.

> - Tier 3 targets may have unusual requirements to build or use, but must not
>   create legal issues or impose onerous legal terms for the Rust project or for
>   Rust developers or users.

The target requires system `clang` and `lld` available as well as custom libc
([musl](https://github.com/access-softek/musl) based) and sysroot, provided [through the build scripts](https://github.com/access-softek/pauth-toolchain-build-scripts/tree/master).

>   - The target must not introduce license incompatibilities.

There are no license implications.

>   - Anything added to the Rust repository must be under the standard Rust
>     license (`MIT OR Apache-2.0`).

Understood.

>   - The target must not cause the Rust tools or libraries built for any other
>     host (even when supporting cross-compilation to the target) to depend
>     on any new dependency less permissive than the Rust licensing policy. This
>     applies whether the dependency is a Rust crate that would require adding
>     new license exceptions (as specified by the `tidy` tool in the
>     rust-lang/rust repository), or whether the dependency is a native library
>     or binary. In other words, the introduction of the target must not cause a
>     user installing or running a version of Rust or the Rust tools to be
>     subject to any new license requirements.

There are no new dependencies or requirements.

>   - Compiling, linking, and emitting functional binaries, libraries, or other
>     code for the target (whether hosted on the target itself or cross-compiling
>     from another target) must not depend on proprietary (non-FOSS) libraries.
>     Host tools built for the target itself may depend on the ordinary runtime
>     libraries supplied by the platform and commonly used by other applications
>     built for the target, but those libraries must not be required for code
>     generation for the target; cross-compilation to the target must not require
>     such libraries at all. For instance, `rustc` built for the target may
>     depend on a common proprietary C runtime library or console output library,
>     but must not depend on a proprietary code generation library or code
>     optimization library. Rust's license permits such combinations, but the
>     Rust project has no interest in maintaining such combinations within the
>     scope of Rust itself, even at tier 3.

The target only relies on open source tools.

>   - "onerous" here is an intentionally subjective term. At a minimum, "onerous"
>     legal/licensing terms include but are *not* limited to: non-disclosure
>     requirements, non-compete requirements, contributor license agreements
>     (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms,
>     requirements conditional on the employer or employment of any particular
>     Rust developers, revocable terms, any requirements that create liability
>     for the Rust project or its developers or users, or any requirements that
>     adversely affect the livelihood or prospects of the Rust project or its
>     developers or users.

No such terms present.

> - Neither this policy nor any decisions made regarding targets shall create any
>   binding agreement or estoppel by any party. If any member of an approving
>   Rust team serves as one of the maintainers of a target, or has any legal or
>   employment requirement (explicit or implicit) that might affect their
>   decisions regarding a target, they must recuse themselves from any approval
>   decisions regarding the target's tier status, though they may otherwise
>   participate in discussions.

Understood.

>   - This requirement does not prevent part or all of this policy from being
>     cited in an explicit contract or work agreement (e.g. to implement or
>     maintain support for a target). This requirement exists to ensure that a
>     developer or team responsible for reviewing and approving a target does not
>     face any legal threats or obligations that would prevent them from freely
>     exercising their judgment in such approval, even if such judgment involves
>     subjective matters or goes beyond the letter of these requirements.

Understood.

> - Tier 3 targets should attempt to implement as much of the standard libraries
>   as possible and appropriate (`core` for most targets, `alloc` for targets
>   that can support dynamic memory allocation, `std` for targets with an
>   operating system or equivalent layer of system-provided functionality), but
>   may leave some code unimplemented (either unavailable or stubbed out as
>   appropriate), whether because the target makes it impossible to implement or
>   challenging to implement. The authors of pull requests are not obligated to
>   avoid calling any portions of the standard library on the basis of a tier 3
>   target not implementing those portions.

`aarch64-unknown-linux-pauthtest target` has std library support, moreover all
`library` tests pass for the target.

> - The target must provide documentation for the Rust community explaining how
>   to build for the target, using cross-compilation if possible. If the target
>   supports running binaries, or running tests (even if they do not pass), the
>   documentation must explain how to run such binaries or tests for the target,
>   using emulation if possible or dedicated hardware if necessary.

Platform support document covers building instructions.

> - Tier 3 targets must not impose burden on the authors of pull requests, or
>   other developers in the community, to maintain the target. In particular,
>   do not post comments (automated or manual) on a PR that derail or suggest a
>   block on the PR based on a tier 3 target. Do not send automated messages or
>   notifications (via any medium, including via `@`) to a PR author or others
>   involved with a PR regarding a tier 3 target, unless they have opted into
>   such messages.

Understood.

>   - Backlinks such as those generated by the issue/PR tracker when linking to
>     an issue or PR are not considered a violation of this policy, within
>     reason. However, such messages (even on a separate repository) must not
>     generate notifications to anyone involved with a PR who has not requested
>     such notifications.

Understood.

> - Patches adding or updating tier 3 targets must not break any existing tier 2
>   or tier 1 target, and must not knowingly break another tier 3 target without
>   approval of either the compiler team or the maintainers of the other tier 3
>   target.

Understood.

>   - In particular, this may come up when working on closely related targets,
>     such as variations of the same architecture with different features. Avoid
>     introducing unconditional uses of features that another variation of the
>     target may not have; use conditional compilation or runtime detection, as
>     appropriate, to let each target run code supported by that target.

Understood.

> - Tier 3 targets must be able to produce assembly using at least one of
>   rustc's supported backends from any host target. (Having support in a fork
>   of the backend is not sufficient, it must be upstream.)

It is expected that the target should be able to compile binaries on any systems
that are capable of compiling `aarch64` code.
2026-06-30 03:41:22 +02:00
Paul Murphy
c340e8a2ba Allow section override when using patchable-function-entries
Sometimes it is necessary to group patchable function entrypoint
records in distinct linker sections. This is the case for some bpf
functions within the linux kernel which shouldn't be visible to
ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form
`prefix_nops,total_nops,record_section`, which places all entry
record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an
optional `section="name"` option to place a function into a specific
section.

This is made possible by llvm attribute `patchable-function-entry-section`
added in llvm 21.
2026-06-29 08:52:28 -05:00
Ben Kimock
96bf9d674b Revert "LLVM 23: Adapt codegen test to moved assume"
This reverts commit 4691890587.
2026-06-27 17:29:27 -04:00
bors
16761606d6 Auto merge of #158455 - JonathanBrouwer:rollup-3fPbHms, r=JonathanBrouwer
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#153697 (Add arg splat experiment initial tuple impl)
 - rust-lang/rust#158360 (Various borrowck cleanups and param_env/opaque_types_defined_by query simplifications for typeck children)
 - rust-lang/rust#158438 (Use rigidness marker in fast_reject)
 - rust-lang/rust#157127 (cg_LLVM: Stop needing an alloca for volatile loads)
 - rust-lang/rust#158376 (Suggest `>=` for `=>` typo in closure and call argument positions)
 - rust-lang/rust#158185 (perf: Make stable_crate_ids reads lock-free after crate loading)
 - rust-lang/rust#158244 (Attribute docs `deprecated` , `warn`, `allow`, `cfg`, `deny`, and `forbid` )
 - rust-lang/rust#158355 (Fixup the refactoring errors in rust-lang/rust#156246)
 - rust-lang/rust#158361 (Move `check_ffi_pure` into the attribute parser)
 - rust-lang/rust#158382 (Add safety section for SliceIndex::get_unchecked(mut))
 - rust-lang/rust#158399 (std: truncate thread names on NetBSD)
 - rust-lang/rust#158418 (Eliminate double length check in `Vec::into_array`)
 - rust-lang/rust#158430 (Guard clone suggestion against empty obligation errors)
 - rust-lang/rust#158446 (Update Enzyme submodule)
 - rust-lang/rust#158448 (Cleanup `NumBuffer` comment and replace `ilog(10)` with `ilog10()`)
2026-06-27 01:14:21 +00:00
bors
ce9954c0cf Auto merge of #155521 - Urgau:runtime-symbols, r=davidtwco
Add lint against invalid runtime symbol definitions



This PR adds a deny-by-default lint againts invalid runtime symbol definitions, those runtime symbols are assumed and used by `core`[^1] and `rustc` with a specific definition.

We have had multiple reports of users tripping over `std` symbols (addressed in a future PR):
 - [Why does `#[no_mangle] fn open() {}` make `cargo t` hang?](https://users.rust-lang.org/t/why-does-no-mangle-fn-open-make-cargo-t-hang/103423)
 - [Pointer becomes misaligned in test with `no_mangle`](https://users.rust-lang.org/t/pointer-becomes-misaligned-in-test-with-no-mangle/126580)

This PR is a second attempt after https://github.com/rust-lang/rust/pull/146505, where T-lang had [some reservations](https://github.com/rust-lang/rust/pull/146505#issuecomment-3492657109) about a blanket lint that does not check the signature, which is now done with this PR, and about linting of `std` runtime symbols when std is not linked, which this PR omits by not including any std runtime symbols (for now). 

## `invalid_runtime_symbol_definitions`

*(deny-by-default)* 

The `invalid_runtime_symbol_definitions` lint checks the signature of items whose symbol name is a runtime symbols expected by `core` differs significantly from the expected signature (like mismatch ABI, mismatch C variadics, mismatch argument count, missing return type, ...).

### Example

```rust,compile_fail
#[unsafe(no_mangle)]
pub fn memcmp() {} // invalid definition of the `memcmp` runtime symbol
```

```text
error: invalid definition of the runtime `memcmp` symbol used by the standard library
 --> a.rs:2:1
  |
4 | fn memcmp() {}
  | ^^^^^^^^^^^
  |
  = note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32`
          found    `fn()`
  = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcmp")]`, or `#[link_name = "memcmp"]`
  = note: `#[deny(invalid_runtime_symbol_definitions)]` on by default
```

### Explanation

Up-most care is required when defining runtime symbols assumed and used by the standard library. They must follow the C specification, not use any standard-library facility or undefined behavior may occur.

The symbols currently checked are `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp` and `strlen`.

## `suspicious_runtime_symbol_definitions`

(warn-by-default, asked in [this comment](https://github.com/rust-lang/rust/pull/155521#issuecomment-4696528297))

The `suspicious_runtime_symbol_definitions` lint checks the signature of items whose symbol name is a runtime symbol expected by `core`.

### Example

```rust
#[unsafe(no_mangle)]
pub extern "C" fn strlen(ptr: *mut f32) -> usize { 0 }
// suspicious definition of the `strlen` function
// `ptr` should be `*const std::ffi::c_char`
```

### Explanation

Up-most care is required when defining runtime symbols assumed and used by the standard library. They must follow the C specification, not use any standard-library facility or undefined behavior may occur.

[^1]: https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library
2026-06-26 18:28:45 +00:00
Jakub Chlanda
23a7ecb97c PR feedback: Teach bootstrap 2026-06-26 13:24:12 +00:00
Jakub Chlanda
124bfe437a PR feedback: Init/Fini 2026-06-26 13:24:12 +00:00
Jakub Chlanda
9da0a3b852 PR feedback: Attributes 2026-06-26 13:24:12 +00:00
Jakub Chlanda
7669c44981 Teach bootstrap how to build rust_test_helpers for pauthtest
Also:
* update tests to force dynamic library when targetting pauthtest
* various test fixes
* introduce end-to-end tests for pauthtest (in run-make)
2026-06-26 13:24:12 +00:00
Jakub Chlanda
157212bdca Add support for init/fini signing and correctly sign extern weak globals
Also add flag for ELF-GOT signing.
2026-06-26 13:24:12 +00:00
Jakub Chlanda
8eccfb14d8 Add pauth attributes and first IR tests
The set of supported attributes is:
function
* "aarch64-jump-table-hardening"
* "ptrauth-auth-traps"
* "ptrauth-calls"
* "ptrauth-indirect-gotos"
* "ptrauth-returns"
module
* "ptrauth-elf-got"
* "ptrauth-sign-personality"
2026-06-26 13:24:10 +00:00
Scott McMurray
9b188dd6c5 cg_LLVM: Stop needing an alloca for volatile loads
And while I'm here, improve the tests to check that the unaligned ones are actually unaligned, since `unaligned_volatile_load::<u8>` doesn't actually test anything.
2026-06-25 20:57:58 -07:00
Scott McMurray
0fc6688ab5 Add a test for current read/write unaligned behaviour 2026-06-25 20:11:29 -07:00
bors
40557f6225 Auto merge of #158419 - jhpratt:rollup-38sJqWx, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#158410 (Update LLVM for Mach-O __LINKEDIT alignment fix.)
 - rust-lang/rust#157397 (cmse: clear padding when crossing the secure boundary)
 - rust-lang/rust#158036 (Add -Zinstrument-mcount=fentry to -Zinstrument-mcount)
 - rust-lang/rust#158330 (llvm: use intrinsics for f16, f32 minimum/maximum)
 - rust-lang/rust#158359 (fix(tests): allow either branch direction in ilog_known_base)
 - rust-lang/rust#158067 (LLVM 23: Adapt codegen test to moved assume)
 - rust-lang/rust#158261 (Move part of the target checking for `#[may_dangle]` to the parser)
 - rust-lang/rust#158358 (Fix invalid E0609 raw pointer deref suggestion inside macros)
 - rust-lang/rust#158392 (delegation: add tests for defaults and infers in generics)
 - rust-lang/rust#158394 (Generate synthetic generic args only for delegation's child segment)
2026-06-25 22:48:30 +00:00
Jacob Pratt
3e2c952def Rollup merge of #158067 - TimNN:moved-assume, r=dianqk
LLVM 23: Adapt codegen test to moved assume

I wasn't completely sure what the important part of this test is - based on the "Make sure we don't create `br` or `select` instructions" comment I assume it's that the `load` is followed ~immediately by the `ret`, and that the presence or absence of the `assume` doesn't really matter (it's been moved up a few lines to before the `load`):

```ll
; Function Attrs
define noundef i32 @foo(ptr noalias nofree noundef align 8 captures(none) dereferenceable(16) %x) unnamed_addr #0 {
start
 %_6 = load ptr, ptr %x, align 8, !nonnull !4, !noundef !4
 %0 = getelementptr inbounds nuw i8, ptr %x, i64 8
 %_7 = load ptr, ptr %0, align 8, !nonnull !4, !noundef !4
 %_8 = icmp ne ptr %_6, %_7
 tail call void @llvm.assume(i1 %_8)
 %_14 = getelementptr inbounds nuw i8, ptr %_6, i64 4
 store ptr %_14, ptr %x, align 8
 %_4 = load i32, ptr %_6, align 4, !noundef !4
 ret i32 %_4
}
 ```

@rustbot label llvm-main

[original CI failure](https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/46608/list?sid=019ed950-c81f-466d-a3bc-2064e6a26719&tab=output)
2026-06-25 17:53:55 -04:00
Jacob Pratt
1f9e9af1a3 Rollup merge of #158359 - HNO3Miracle:fix-riscv-ilog-known-base, r=petrochenkov
fix(tests): allow either branch direction in ilog_known_base

Fixes rust-lang/rust#158339.

`tests/codegen-llvm/ilog_known_base.rs` checks that `checked_ilog` with a known power-of-two base is lowered through the faster `llvm.ctlz` path.

On `riscv64gc-unknown-linux-gnu`, LLVM emits the zero check with the opposite branch direction (`icmp eq i32 %val, 0`) from what the test currently expects (`icmp ne i32 %val, 0`). Both forms still guard the same `llvm.ctlz` fast path, so this relaxes the FileCheck pattern to accept either comparison direction.

This also fixes the `checked_ilog16` FileCheck variable to use the `DIV4` result it just matched.

Tested:

```sh
./x test --stage 2 tests/codegen-llvm/ilog_known_base.rs
```
2026-06-25 17:53:54 -04:00
Jacob Pratt
a82172d9ca Rollup merge of #158036 - pmur:murp/add-fentry, r=folkertdev
Add -Zinstrument-mcount=fentry to -Zinstrument-mcount

fentry is essentially a simpler version of mcount where the counting function is called before any other function prologue actions happen.

fentry is still used by the linux x86-64 kernel. It's unclear if or when patchable-function-entry will replace it. It is also used by clang for some x86-64 mingw toolchains.

This is only supported on some x86, x86-64, and s390x targets.
2026-06-25 17:53:53 -04:00
Urgau
7411873a9d Fix invalid memcpy definition in codegen test and UI tests 2026-06-25 23:53:43 +02:00
Tim Neumann
4691890587 LLVM 23: Adapt codegen test to moved assume 2026-06-25 11:01:49 +02:00
HNO3Miracle
e81423abe7 Allow either branch direction in ilog_known_base
Signed-off-by: HNO3Miracle <xiangao.or@isrc.iscas.ac.cn>
2026-06-24 20:54:21 +08:00
David Wood
cfc4211b6e codegen_ssa: multiply scalable vec size by vscale
When emitting a `memcpy` for a scalable vector, the size computed by
rustc (`num_vectors * element_count * element_ty`), since
rust-lang/rust#157915, needs to be multiplied by `vscale`.
2026-06-22 15:06:35 +00:00
usamoi
d8cf805f9a parse attrs if a loop's parent hir node is a stmt 2026-06-21 21:23:45 +08:00
Jonathan Brouwer
5cdff6b1c8 Rollup merge of #157829 - durin42:llvm-23-pow-fix, r=mati865
tests: adapt two tests for LLVM 23 changes

LLVM 23 recently changed SimplifyCFG to avoid integer lookup tables, and that perturbed these two tests in ways that look harmless to me.
2026-06-17 22:36:23 +02:00
Jonathan Brouwer
47ce0db55b Rollup merge of #157788 - PiJoules:multiple-sanitizer-flags, r=petrochenkov
Accumulate multiple -Zsanitizer target modifiers

When passing multiple `-Zsanitizer` flags to the compiler (e.g., `-Zsanitizer=address -Zsanitizer=shadow-call-stack`), the options parser was overwriting the previous values in `target_modifiers` instead of accumulating them. This resulted in only the last sanitizer being recorded in the crate metadata's target modifiers, even though the frontend correctly enabled all of them. The only way to provide multiple sanitizers is to combine them into a comma-separated list passed to a single `-Zsanitizer=` flag, but this doesn't fit very well into the GN build system where different targets may pass different combinations of sanitizer flags.

Consequently, this caused spurious "incompatible target modifiers" ABI mismatch errors when linking against dependencies compiled with accumulated flags.

Fix this by entry-modifying the `target_modifiers` map to accumulate the sanitizers as a comma-separated list when the option is `sanitizer`.
2026-06-17 22:36:21 +02:00
Paul Murphy
6ce0650633 Add -Zinstrument-mcount=fentry to -Zinstrument-mcount
fentry is essentially a simpler version of mcount where the
counting function is called before any other function prologue
actions happen.

fentry is still used by the linux x86-64 kernel. It's unclear if
or when patchable-function-entry will replace it. It is also used
by clang for some x86-64 mingw toolchains.

This is only supported on some x86, x86-64, and s390x targets.
2026-06-17 13:09:33 -05:00
Jacob Pratt
ebc3b52205 Rollup merge of #157681 - pmur:murp/add-instrument_fn-attr, r=oli-obk,mejrs
Add instrument_fn attribute

This attribute enables or disables function instrumentation when using `-Zinstrument-xray` or `-Zinstrument-mcount`.

It supports the following usage:

`#[instrument_fn = "on|off"]`

For XRay, "on" is equivalent to always instrument, and "off" is equivalent to never instrumenting.

For mcount, "on" has no effect. "off" disables instrumentation of the function.

This is tracked by rust-lang/rust#157081, and related to the pending rfc rust-lang/rfcs#3917, and earlier as part mcp rust-lang/compiler-team#561
2026-06-16 22:10:30 -04:00
Paul Murphy
f638abc260 Add instrument_fn attribute
This attribute enables or disables function instrumentation
when using `-Zinstrument-xray` or `-Zinstrument-mcount`.

It supports the following usage:

`#[instrument_fn = "on|off"]`

For XRay, "on" is equivalent to always instrument, and "off" is
equivalent to never instrumenting.

For mcount, "on" has no effect. "off" disables instrumentation
of the function.
2026-06-16 17:11:03 -05:00
Jonathan Brouwer
bf0dfb606b Rollup merge of #157306 - vadorovsky:vad/llvm-codegen-bpf-abi-indirect-return, r=nagisa
tests: codegen-llvm: Expect the new mangling scheme in bpf-abi-indirect-return

[The new Rust symbol mangling](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html) uses prefix `_R` instead of `@_ZN`.

Instead of keeping the test as `only-bpf`, use minicore. This way we make sure it will never get outdated again.

r? @nagisa
2026-06-16 22:11:03 +02:00
Leonard Chan
115338beb8 rustc_session: accumulate multiple -Zsanitizer target modifiers
When passing multiple `-Zsanitizer` flags to the compiler (e.g.,
`-Zsanitizer=address -Zsanitizer=shadow-call-stack`), the options parser
was overwriting the previous values in `target_modifiers` instead of
accumulating them. This resulted in only the last sanitizer being
recorded in the crate metadata's target modifiers, even though the
frontend correctly enabled all of them.

The only way to provide multiple sanitizers was to combine them into a
comma-separated list passed to a single `-Zsanitizer=` flag, but this
does not fit well into the GN build system where different targets may
pass different combinations of sanitizer flags.

Consequently, this caused spurious "incompatible target modifiers"
ABI mismatch errors when linking against dependencies compiled with
accumulated flags (e.g., `-Zsanitizer=address,shadow-call-stack`).

Fix this by entry-modifying the `target_modifiers` map to accumulate
the sanitizers as a comma-separated list when the option is
`sanitizer`.

Also add a codegen test verifying that both CFI and SafeStack
attributes/metadata are present when enabled together via multiple
flags.

Test: ./x.py test tests/codegen-llvm/sanitizer/multiple-sanitizers.rs
2026-06-16 18:07:05 +00:00
bors
b998449636 Auto merge of #156816 - saethlin:loop-attributes, r=JonathanBrouwer,folkertdev
Add unstable loop unrolling hint attributes



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

This adds as new attribute `#[unroll]`/`#[unroll(full)]`/`#[unroll(never)]`/`#[unroll(16)]` (or any u32).

`#[unroll]` is behind a new feature gate `#![feature(loop_hints)]` because I intend to add an attribute for loop vectorization as well. If a user wants to turn off loop unrolling to locally minimize code size, LLVM may vectorize the loop even though it isn't unrolled which can produce a similar code size explosion.
2026-06-16 08:40:13 +00:00
Jacob Pratt
fcfdcb86a3 Rollup merge of #157627 - folkertdev:remove-llvm-va_end, r=RalfJung
remove LLVM `va_end` calls

tracking issue: https://github.com/rust-lang/rust/issues/44930

The operation is a no-op, so we skip it.
2026-06-15 16:16:08 -04:00
Folkert de Vries
d297af408d remove LLVM va_end calls
The operation is a no-op, so we skip it.
2026-06-15 19:52:50 +02:00
Jonathan Brouwer
36c0285e93 Rollup merge of #157029 - ElliottjPierce:stabilize-feature-float_algebraic, r=RalfJung
stabilize feature `float_algebraic`

Closes rust-lang/rust#136469

Thanks to @RalfJung for getting the stabilization process started and asking me to draft the stabilization PR for the `float_algebraic` feature. This will be my first contribution to rust! I've done my best to follow the various guides for stabilization PRs, but this is my first one, so do give it a careful look. The only place left that includes "float_algebraic" is line 8202  of "src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs", but I'm assuming that's fine.
2026-06-15 13:33:24 +02:00
Elliott Pierce
d69bd08f96 stabilize feature float_algebraic
* stabilize feature float_algebraic
* fixed algrebracis for `f16` and `f128`
2026-06-15 00:56:07 +00:00
Jacob Pratt
4532a3ab71 Rollup merge of #157791 - kohsine:pclmulqdq-inlining, r=folkertdev
Add regression test for pclmulqdq inlining across target feature

Regression test for https://github.com/rust-lang/rust/issues/139029.

Checks that pclmulqdq intrinsics inline across target_feature.
2026-06-13 23:56:19 -04:00
kohsine
59902d528d remove comment 2026-06-13 11:06:59 -04:00
Kevin Oh
2bed3cc40c update comment
Co-authored-by: Folkert de Vries <flokkievids@gmail.com>
2026-06-13 10:59:55 -04:00
kohsine
bf8a123858 use next and count directives to check calls are happening inside function body 2026-06-13 10:57:36 -04:00
Jacob Pratt
c5ed1a7f73 Rollup merge of #157802 - veluca93:optimize-attr-closure, r=mejrs,wesleywiser
Ensure that optimize attributes on closures are inherited by the shim.

Tracking issue: https://github.com/rust-lang/rust/issues/54882
Stabilization PR: https://github.com/rust-lang/rust/pull/157273
2026-06-13 04:06:05 -04:00
Luca Versari
0959e4d697 Ensure that optimize attributes on closures are inherited by the shim. 2026-06-12 23:08:08 +02:00