Commit Graph

656 Commits

Author SHA1 Message Date
Jacob Pratt
f25db1a66f Rollup merge of #158693 - Sa4dUs:offload-typeck, r=ZuseZ4
Add type-check to offload intrinisc calls

As discussed in [zulip](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20Inferring.20return.20type.20from.20a.20function.20passed.20to.20an.20intr.2E.2E.2E), in order to support sufficiently generic kernel functions, we need to move away from checking arguments and return types solely via traits on the intrinsic declaration. Instead, these validation checks are now performed during the type-checking phase.

r? @ZuseZ4
2026-07-29 20:48:13 -04:00
Jacob Pratt
acb7f30f6f Rollup merge of #157669 - 1c3t3a:cfi-diag-mode, r=rcvalle
cfi: add diag mode support

Currently a Rust CFI failure only inserts a ud2. However, for clang we have the option for a helpful diagnostic message that explains the violation and is especially helpful for fixing it. This message works through hooking the UBSan runtime and calling into it with the necessary information for a helpful error message. In clang, this is enabled via `-fno-sanitize-trap=cfi`.

This change adds the same behavior to rustc's CFI. Instead of a `no-sanitize-trap` flag, we added `-Z cfi-mode={diag|trap}`, with trap as the default. The diag mode will print the following error message for a violation:

```
tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1: runtime error: control flow integrity check for type fn(i32, i32) -> i32 failed during indirect function call
fn_ptr_type_mismatch.ecd806f409c5c1fc-cgu.0: note: fn_ptr_type_mismatch::add_one defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1
```

r? @rcvalle
2026-07-29 20:48:11 -04:00
Sa4dUs
f6e39fbff3 fix and add tests 2026-07-29 20:57:29 +03:00
Jonathan Brouwer
1a9b3a7705 Rollup merge of #159632 - rcvalle:rust-cfi-fix-159299, r=bjorn3
CFI: Add support for the adt_const_params feature

Adds support for encoding constants of types allowed by the adt_const_params and unsized_const_params features (i.e., char, str, tuple, array, slice, struct, enum, and reference values) as literal arguments, and fixes the encoding of bool values to be 0 and 1, and of negative integer values to be their decimal values preceded by n (fixes rust-lang/rust#159299).
2026-07-29 14:10:31 +02:00
Bastian Kersting
3955b030e0 Refactor to -Zsanitizer-cfi-diag={false,true} and -Zsanitizer-cfi-recover={false,true} 2026-07-28 21:10:13 +00:00
Bastian Kersting
aea066233b cfi: add diag mode support
Currently a Rust CFI failure only inserts a ud2. However, for clang
we have the option for a helpful diagnostic message that explains the
violation and is especially helpful for fixing it. This message works
through hooking the UBSan runtime and calling into it with the
necessary information for a helpful error message. In clang, this is
enabled via -fno-sanitize-trap=cfi.

This change adds the same behavior to rustc's CFI. Instead of a
no-sanitize-trap flag, we added -Z cfi-mode={diag|trap}, with trap
as the default. The diag mode will print the following error message
for a violation:

```
tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1: runtime error: control flow integrity check for type fn(i32, i32) -> i32 failed during indirect function call
fn_ptr_type_mismatch.ecd806f409c5c1fc-cgu.0: note: fn_ptr_type_mismatch::add_one defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1
```
2026-07-28 21:10:12 +00:00
Mike Hommey
6d9e4076ff codegen: skip stores for entirely-uninit constant aggregate fields
MIR GVN propagates MaybeUninit::uninit() as `const <uninit>` in aggregate
constructions and codegen emits a memcpy from an `[N x i8] undef` global for
each such field, which LLVM materializes as zero-initialization.

We extract the existing `all_bytes_uninit` skip already present for
`Rvalue::Use` and `Rvalue::Repeat` to a separate helper function, and use
it in the `Rvalue::Aggregate` field loop.
2026-07-28 18:48:00 +09:00
Mike Hommey
7158341ec7 Revert "codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants"
This reverts commit ed9de1e466.
2026-07-28 18:47:39 +09:00
Mike Hommey
506de4777f Revert "codegen: handle OperandValue::Uninit in codegen_return_terminator"
This reverts commit 9e9467adc6.
2026-07-28 18:47:34 +09:00
Jacob Pratt
e2f5373428 Rollup merge of #159450 - amirHdev:add-codegen-test-enum-clone, r=chenyukang
Add codegen test for enum clone

Closes rust-lang/rust#69174
2026-07-28 01:38:34 -04:00
bors
ad0c9dce27 Auto merge of #159317 - workingjubilee:aarch64-bool-callconv, r=davidtwco
Fix `bool` calling convention for aarch64, etc.



We have been making a broad assumption about the way `bool` should be handled that *may* be correct for Rust calling Rust but is wildly incorrect for cross-language FFI calls. The ABI of `bool` is generally poorly-specified in any C psABI, and often deliberately allows for deviation after the first 8 bits.

This has surfaced as a bug that can corrupt Rust programs on aarch64, but it is a potential latent bug when it comes to every ABI. The simplest solution is to simply stop applying the special case when generating `bool`'s ArgAttributes. This yields control to the later ABI implementations, which may then sign or zero extend the `bool` (or not) according to their needs.
2026-07-27 09:35:03 +00:00
bors
dfbea5bc94 Auto merge of #159966 - JonathanBrouwer:rollup-efqUEIj, r=JonathanBrouwer
Rollup of 28 pull requests

Successful merges:

 - rust-lang/rust#159638 (bootstrap: Split the `Step` trait into multiple traits)
 - rust-lang/rust#159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations)
 - rust-lang/rust#159837 (line-tables-only test: check that the line number matches the function name)
 - rust-lang/rust#159946 (Update Enzyme submodule to imporve llvm-cov)
 - rust-lang/rust#159962 (miri subtree update)
 - rust-lang/rust#156570 (tests: extend remap-path-prefix-std to all stdlib rlibs)
 - rust-lang/rust#159617 (Fix up `#[linkage]` target checking)
 - rust-lang/rust#159633 (Improve workings of attribute suggestions)
 - rust-lang/rust#159733 (std: Switch implementations of `thread_local!` for WASI)
 - rust-lang/rust#159783 (Check unsafe impls on safe EIIs)
 - rust-lang/rust#159810 (Add tuple never coercion collection regression test)
 - rust-lang/rust#159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - rust-lang/rust#159846 (Implement `str::copy_from_str`)
 - rust-lang/rust#159849 (rustc_parse: Stop returning `Option` from statement parsing)
 - rust-lang/rust#159853 (Updated expect messages for `CString` struct and method documentation)
 - rust-lang/rust#159875 (More cleanup in `rustc_attr_parsing`)
 - rust-lang/rust#159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide)
 - rust-lang/rust#159891 (Split multiline derives into std/rustc macros)
 - rust-lang/rust#159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups)
 - rust-lang/rust#159895 (rustc-dev-guide subtree update)
 - rust-lang/rust#159902 (Clarify that the expected runtime symbols signature is for the current target only)
 - rust-lang/rust#159914 (Fix error in diagnostic on_unmatched_args)
 - rust-lang/rust#159917 (spare capacity mut constification)
 - rust-lang/rust#159918 (rename abort_unwind → abort_on_unwind)
 - rust-lang/rust#159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.)
 - rust-lang/rust#159936 (Minor `rustc_ast::ast` doc cleanups)
 - rust-lang/rust#159945 (Update expect messages in library/core/src/ptr/non_null.rs)
 - rust-lang/rust#159950 (Add CFI tests for return types and never type)
2026-07-26 23:28:05 +00:00
bors
5e2e8734b6 Auto merge of #158901 - veluca93:optimize-attr-closure-inherit, r=wesleywiser,scottmcm
Closures inherit #[optimize] from the enclosing function by default.

Tracking issue: https://github.com/rust-lang/rust/issues/54882
Stabilization PR: https://github.com/rust-lang/rust/pull/157273
2026-07-26 17:03:38 +00:00
Jonathan Brouwer
e6a1a8fce5 Rollup merge of #159950 - Darksonn:cfi-return-types, r=folkertdev
Add CFI tests for return types and never type

In a few different conversations, the CFI types of various functions has come up. First, the CFI type of returning `!` came up in https://github.com/rust-lang/rust/issues/159446#issuecomment-5011154213, where we found that it doesn't have the same CFI type as returning `()`, which it probably should.

Then in rust-lang/rust#159935, I wanted to make sure that this does not change the CFI type of functions when `*mut c_void` appears as an argument. Luckily it does not since it's a lang item, but there's no test for this case.

Thus, add tests for all of these cases and a few others.

AI assistance was involved with writing the test.
2026-07-26 15:47:30 +02:00
Alice Ryhl
8e0f2e9345 Add CFI tests for return types and never type
Verifies that LLVM emits correct CFI type metadata identifiers for
functions returning `()`, `!`, `*mut c_void`, `*const c_void`, `*mut ()`,
`*mut u8`, and `*mut i8`:
- `_ZTSFvvE` (`fn()`)
- `_ZTSFu5nevervE` (`fn() -> !`)
- `_ZTSFPvS_E` (`fn(*mut c_void) -> *mut c_void` and `fn(*mut ()) -> *mut ()`)
- `_ZTSFPKvS0_E` (`fn(*const c_void) -> *const c_void`)
- `_ZTSFPu2u8S0_E` (`fn(*mut u8) -> *mut u8`)
- `_ZTSFPu2i8S0_E` (`fn(*mut i8) -> *mut i8`)
2026-07-26 07:00:43 +00:00
Luca Versari
cca3d28385 Closures inherit #[optimize] from the enclosing function by default. 2026-07-25 20:42:30 +02:00
Mike Hommey
9e9467adc6 codegen: handle OperandValue::Uninit in codegen_return_terminator
When adding `OperandValue::Uninit` to skip stores for entirely-uninit
constants, we missed the `PassMode::Direct | PassMode::Pair` branch of
`codegen_return_terminator`, which called `immediate_or_packed_pair`
unconditionally. A function directly returning an all-uninit value (e.g.
`MaybeUninit::uninit()`) would hit that branch and ICE in
`OperandRef::immediate`, as reported against tokio and reduced by tmiasko.
2026-07-26 00:07:52 +09:00
Jacob Pratt
85fbe5a37f Rollup merge of #159764 - folkertdev:use-minicore-simd, r=jieyouxu
use `minicore::simd::Simd` more

follow-up to https://github.com/rust-lang/rust/pull/159656.

I've used `grep -rlZ "repr_simd" . | xargs -0 grep -l "use minicore"` to find all test files that used both `repr_simd` and `use minicore`, they now all use `minicore::simd` to `repr_simd` is no longer needed for them.
2026-07-23 19:18:47 -04:00
Folkert de Vries
afb2e9cb0e use minicore::simd::Simd more 2026-07-23 12:22:51 +02:00
bors
e7795af6d2 Auto merge of #157797 - glandium:uninit, r=oli-obk
codegen: skip stores for entirely-uninit constant aggregate fields



MIR GVN (since rust-lang/rust#147827) propagates MaybeUninit::uninit() as `const <uninit>` in aggregate constructions. Without this fix, codegen would emit a memcpy from an `[N x i8] undef` global for each such field, which LLVM materializes as zero-initialization.

This mirrors the existing `all_bytes_uninit` skip already present for `Rvalue::Use` (added in rust-lang/rust#147827) into the `Rvalue::Aggregate` field loop.

Fixes: rust-lang/rust#157743
2026-07-22 22:50:42 +00:00
bors
6f72b5dd5f Auto merge of #143208 - Mark-Simulacrum:skip-noop-cleanup, r=oli-obk
Apply RemoveNoopLandingPads post-monomorphization



On Cargo this cuts ~5% of the LLVM IR lines we generate (measured with -Cno-prepopulate-passes).

Closes https://github.com/rust-lang/rust/issues/159399.
2026-07-22 19:33:32 +00:00
Folkert de Vries
d7ea382797 Stabilize c_variadic 2026-07-22 11:42:09 +02:00
Folkert de Vries
3feb78f7ba define a Simd type in minicore 2026-07-21 14:09:56 +02:00
Ramon de C Valle
679bdc1180 CFI: Add support for the adt_const_params feature
Adds support for encoding constants of types allowed by the
adt_const_params and unsized_const_params features (i.e., char, str,
tuple, array, slice, struct, enum, and reference values) as literal
arguments, and fixes the encoding of bool values to be 0 and 1, and of
negative integer values to be their decimal values preceded by n.
2026-07-20 20:32:23 -07:00
Mike Hommey
ed9de1e466 codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants
MIR GVN propagates MaybeUninit::uninit() as `const <uninit>` in aggregate
constructions and codegen emits a memcpy from an `[N x i8] undef` global for
each such field, which LLVM materializes as zero-initialization.

Instead of special-casing `all_bytes_uninit` at each call site, add a new
`OperandValue::Uninit` variant that `eval_mir_constant_to_operand` returns for
any all-bytes-uninit constant. `store_with_flags` is a no-op for this variant,
so the fix applies uniformly across `Rvalue::Use`, `Rvalue::Repeat`, and
`Rvalue::Aggregate` without per-site checks. The variant propagates through
field extraction and transmutes, and is handled appropriately at the remaining
call sites (function arguments, discriminant reads, debug info, etc.).
2026-07-21 11:46:36 +09:00
Jacob Pratt
2408dfeac2 Rollup merge of #159129 - amirHdev:add-codegen-test-signed-nonzero-matches, r=nnethercote
Add codegen test for signed nonzero matches

Closes rust-lang/rust#84311
2026-07-20 02:59:40 -04:00
Mark Rousskov
f513294c00 Remove no-op cleanups on MIR post-monomorphization
This speeds up LLVM and improves codegen overall. As an example, for
cargo this cuts ~5% of the LLVM IR lines we generate (measured with
-Cno-prepopulate-passes).
2026-07-18 10:21:15 -04:00
Jubilee Young
1f59b1e6c0 tests: Include bools in integer arg-extension test 2026-07-17 15:21:40 -07:00
Amirhossein Akhlaghpour
f849721dbd chore: add codegen test for enum clone
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
2026-07-17 18:08:12 +03:30
Jonathan Brouwer
3a1f42a32c Rollup merge of #159404 - dpaoliello:varargarm64ec, r=folkertdev
[aarch64][win] Pass oversized c-variadic args indirectly on Arm64EC

On Arm64EC the variadic portion of a c-variadic call must follow the MS x64 ABI: any argument that does not fit in 8 bytes, or whose size is not 1, 2, 4, or 8 bytes, is passed by reference. rustc's `va_arg` implementation already reads such arguments indirectly, but the caller side in `aarch64::compute_abi_info` passed a scalar `i128` by value (it is not an aggregate, so it bypassed `classify_arg`). The callee then dereferenced the inline value as a pointer, causing an access violation (0xC0000005) at runtime.

Mark variadic-tail arguments larger than 8 bytes, or whose size is not a power of two, as indirect on Arm64EC so the caller and the `va_arg` reader agree. Fixed arguments are unaffected: a fixed `i128` is still passed by value, matching MSVC and Clang.

Add a codegen test verifying that a variadic `i128` is passed as a pointer while a fixed `i128` is passed by value.
2026-07-17 15:22:12 +02:00
Jonathan Brouwer
223b78e0f0 Rollup merge of #159391 - nikic:llvm23-test-updates, r=cuviper
Update tests for LLVM 23

Fixes https://github.com/rust-lang/rust/issues/158880.
Fixes https://github.com/rust-lang/rust/issues/158572.
Fixes https://github.com/rust-lang/rust/issues/156050.

One test is disabled on LLVM 23, because it's no longer optimized as expected. Tracked in https://github.com/rust-lang/rust/issues/154141 and https://github.com/llvm/llvm-project/issues/209216.
2026-07-17 15:22:09 +02:00
Jonathan Brouwer
e22573bdf5 Rollup merge of #159375 - ferrocene:jyn/codegen-tests-2021, r=jieyouxu
make a couple codegen-llvm tests compatible with 2021 edition

previously they failed for simple syntax reasons.
2026-07-16 21:01:59 +02:00
Daniel Paoliello
14713e5af8 [aarch64][win] Pass oversized c-variadic args indirectly on Arm64EC
On Arm64EC the variadic portion of a c-variadic call must follow the MS
x64 ABI: any argument that does not fit in 8 bytes, or whose size is not
1, 2, 4, or 8 bytes, is passed by reference. rustc's `va_arg`
implementation already reads such arguments indirectly, but the caller
side in `aarch64::compute_abi_info` passed a scalar `i128` by value (it
is not an aggregate, so it bypassed `classify_arg`). The callee then
dereferenced the inline value as a pointer, causing an access violation
(0xC0000005) at runtime.

Mark variadic-tail arguments larger than 8 bytes, or whose size is not a
power of two, as indirect on Arm64EC so the caller and the `va_arg`
reader agree. Fixed arguments are unaffected: a fixed `i128` is still
passed by value, matching MSVC and Clang.

Add a codegen test verifying that a variadic `i128` is passed as a
pointer while a fixed `i128` is passed by value.
2026-07-16 10:47:53 -07:00
Nikita Popov
d4a24cd6e1 Adjust codegen test for LLVM 23
The assume here is not really relevant to the purpose of the test,
and it's position changed in LLVM 23.
2026-07-16 16:35:50 +02:00
Nikita Popov
e2159107f6 Update global_asm tests for LLVM 23
There is now only a single "module asm", not one before each line.
2026-07-16 16:35:37 +02:00
jyn
4b0cd8edd9 make a couple codegen-llvm tests compatible with 2021 edition
previously they failed for simple syntax reasons.
2026-07-16 12:23:20 +02:00
Jonathan Brouwer
be99e0625a Rollup merge of #159331 - zmodem:ignore_llvm_version_fix, r=mati865
Fix ignore-llvm-version directive in codegen-llvm/array-equality.rs

There needs to be spaces around the dash, otherwise it doesn't work as a range (which matters now that LLVM trunk is 24).
2026-07-15 16:17:14 +02:00
Jonathan Brouwer
298175f7a9 Rollup merge of #159239 - amirHdev:add-codegen-test-rem-match-unreachable, r=mejrs
Add codegen test for remainder match

Closes rust-lang/rust#93514
2026-07-15 16:17:12 +02:00
Hans Wennborg
9e25e3aab5 Fix ignore-llvm-version directive in codegen-llvm/array-equality.rs
There needs to be spaces around the dash, otherwise it doesn't work as a
range (which matters now that LLVM trunk is 24).
2026-07-15 14:02:15 +02:00
Jacob Pratt
7347c6d3d4 Rollup merge of #156712 - jchlanda:jakub/pac_config, r=davidtwco
Pointer authentication config and user facing options

This patch brings:
* unified handling of pointer authentication options through:
  `-Zpointer-authentication`, with possible values:
  `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`,
  `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`,
  `init-fini-address-discrimination`, `return-addresses`. Toggled with
  `+`/`-`.
* centralized handling of pointer authentication features. Session holds
  `pointer_auth_config: Option<PointerAuthConfig>`
* encapsulation of schema for function pointers and init/fini through
  `PointerAuthSchema`. This allowed for retiring of `PacMetadata`.
* refactor enabling of pointer authentication in code, instead of
  relying on the target (`pauthtest`) use the session
2026-07-15 06:12:10 -04:00
Jonathan Brouwer
b10b737aac Rollup merge of #159269 - fneddy:disable-test-rltf, r=folkertdev
disable range-len-try-from.rs on s390x

This optimisation is currently broken on s390x[^1]. It looks like a big-endian issue in general. but as we only know about the test fails on s390x we only disable it there.

Should be reenabled when the problem is fixed and llvm backend is updated.

[^1]: https://github.com/llvm/llvm-project/issues/208712
2026-07-14 16:49:11 +02:00
Jakub Chlanda
ae91cf7db7 Update tests to use // ignore-tidy-file-linelength 2026-07-14 09:13:12 +00:00
Jakub Chlanda
f283bde834 Convert -Zpointer-authentication to target modifier
Also improve the API design of pointer_authentication_functions, by
making it return Option<&PointerAuthSchema>, rather than bool.
2026-07-14 09:13:12 +00:00
Jakub Chlanda
00f9612daf Document -Zpointer-authentication option 2026-07-14 09:13:12 +00:00
Jakub Chlanda
03e9cf180e Extend version support with C++ specifics 2026-07-14 08:48:56 +00:00
Jakub Chlanda
abd56e9039 Pointer authentication config and user facing options
This patch brings:
* unified handling of pointer authentication options through:
  `-Zpointer-authentication`, with possible values:
  `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`,
  `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`,
  `init-fini-address-discrimination`, `return-addresses`. Toggled with
  `+`/`-`.
* centralized handling of pointer authentication features. Session holds
  `pointer_auth_config: Option<PointerAuthConfig>`
* encapsulation of schema for function pointers and init/fini through
  `PointerAuthSchema`. This allowed for retiring of `PacMetadata`.
* refactor enabling of pointer authentication in code, instead of
  relying on the target (`pauthtest`) use the session
2026-07-14 08:48:56 +00:00
Eddy (Eduard) Stefes
7139a2b071 disable range-len-try-from.rs on s390x
This optimisation is currently broken on s390x[^1].
It looks like a big-endian issue in general. but as
we only know about the test fails on s390x we only
disable it there.

Should be reenabled when the problem is fixed and llvm
backend is updated.

[^1]: https://github.com/llvm/llvm-project/issues/208712
2026-07-14 08:42:45 +02:00
Jacob Pratt
e59b99943f Rollup merge of #159248 - workingjubilee:remove-mutable-noalias, r=Urgau
compiler: Remove `-Zmutable-noalias`

Let us mark the end of an era. The `noalias` optimization has been working relatively well for some time now. There may still be issues to sort out with `noalias`. If so, those are mostly on LLVM's side, where it may need to have a better model of what `noalias` means as that is necessary for soundly inferring it. We also may need to not add `noalias` somewhere we currently do, if our semantics do not actually match that. Either way, it doesn't seem useful to configure on a compilation-wide basis.
2026-07-14 00:15:24 -04:00
Jonathan Brouwer
490097dc9a Rollup merge of #157706 - jdonszelmann:deny-todo, r=wafflelapkin
Deny `todo!()` in tidy

Implements https://github.com/rust-lang/compiler-team/issues/999

Part of https://github.com/rust-lang/rust/issues/158173
2026-07-13 20:17:57 +02:00
Jubilee Young
1ccd7e1391 Remove noalias tests 2026-07-13 10:14:58 -07:00