Commit Graph

677 Commits

Author SHA1 Message Date
Jacob Pratt
9e0b9bc6cd Rollup merge of #158885 - folkertdev:complex-layout, r=workingjubilee
Add `core::num::Complex`

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

See also [#t-compiler > representing `_Complex`](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/representing.20.60_Complex.60/with/608308993). The RFC states that the `Complex` type should match the ABI of `_Complex` in C, but provides little detail on how to actually achieve this. We concluded that `repr(complex)` is probably the best approach. Like clang, that means we "desugar" the representation early: `_Complex` is not natively represented in LLVM IR.

I've derived the ABI from `clang` for 28 targets, a decent sample of what we actually support. For now I'm only actually testing `x86_64` because (as you'll see) updating the tests is quite labor-intensive. If we're happy with this direction I can fill more of them in, likely in a separate PR.

The libs side of the type is very bare-bones: I'm not as interested in that part. Others can fill in the various instances, methods, write tests for those, and improve the docs.

r? workingjubilee
2026-08-13 18:16:12 -04:00
Jacob Pratt
8d82dada19 Rollup merge of #161040 - SomeFlyingThing:agent/audit-codegen-hints, r=joboet
Optimize CStr backing slice bounds checks

Hint that Cstr is non empty bcs it always contains the null byte.     Byte-zero access reduces from 27 to 4 bytes
2026-08-13 18:16:11 -04:00
Folkert de Vries
534309dd12 Complex return on x86 2026-08-13 19:32:19 +02:00
Folkert de Vries
130ae0bd00 Implement and test x86_64 Complex 2026-08-13 19:32:19 +02:00
Folkert de Vries
2567434237 disable most revisions 2026-08-13 19:32:18 +02:00
Folkert de Vries
3238bbfdaf add CHECK lines and revisions 2026-08-13 19:32:18 +02:00
Folkert de Vries
3512f08ab3 add complex-abi.rs test 2026-08-13 19:32:18 +02:00
bjorn3
16dd590002 Don't use extern "unadjusted" outside of LLVM intrinsics in tests 2026-08-13 14:17:36 +02:00
SomeFlyingThing
5f4b091827 Optimize CStr backing slice bounds checks 2026-08-13 02:56:27 -07:00
Marcelo Dominguez
4d52fe93a2 Add 3-pass compilation to support generics and remove no_mangle attr 2026-08-12 18:06:00 +03:00
Adwin White
10e95f40c5 disable some tests for ohos target 2026-08-11 14:13:19 +08:00
SomeFlyingThing
8109a4b8cf Optimize slice::contains for one-byte BytewiseEq types 2026-08-07 21:35:01 -07:00
Jieyou Xu
44d291e788 Update attr name in #[unroll] codegen-llvm tests 2026-08-06 09:23:37 +08:00
Ralf Jung
9c37be358b fix various tests 2026-08-05 13:45:49 +02:00
Cai Congcong
623d78a6d0 set no_mangle_generic_items deny by default 2026-08-05 13:39:16 +02:00
Jakub Beránek
6c4c536357 Rollup merge of #160184 - pmur:murp/add-mcount-opts, r=mati865
Add -Zinstrument-mcount={fentry-nop-record,fentry-record}

The linux kernel still uses fentry for x86 and s390x arches. s390x depends entirely on the compiler to record and nop these sections.

This facilitates support for inserting nop's and/or recording the location of each mcount call in a special section named `__mcount_loc`.

These attributes are currently only supported with fentry on the s390x target, otherwise they are quietly ignored (except on s390x).
2026-08-04 11:10:13 +02:00
Jakub Beránek
01296edd3b Rollup merge of #159535 - SomeFlyingThing:optimize-slice-contains-bytewise, r=Mark-Simulacrum
Optimize slice::contains for bytewise types

generalize the SliceContains implementation from u8 to all types implementing UnsignedBytewiseOrd since these types have a one byte representation compatible with the
memchr implementation
2026-08-04 11:10:12 +02:00
Jonathan Brouwer
8b35b28188 Rollup merge of #159499 - AayushMainali-Github:main, r=jieyouxu
tests: prefer max-llvm-major-version over open LLVM ranges

Per review, take option 3: replace open `ignore-llvm-version` ranges with `max-llvm-major-version`. Left gdb `X - 99.0` ranges alone so CI's older gdb still runs those tests.

Fixes rust-lang/rust#159338.
2026-08-02 16:19:30 +02:00
Paul Murphy
3874adb16b Add -Zinstrument-mcount={fentry-nop-record,fentry-record}
The linux kernel still uses fentry for x86 and s390x arches.
s390x depends entirely on the compiler to record and nop
these sections.

This facilitates support for inserting nop's and/or recording the
location of each mcount call in a special section named `__mcount_loc`.

These attributes are currently only supported with fentry on the s390x
target, otherwise they are quietly ignored (except on s390x).
2026-07-30 15:18:09 -05:00
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
AayushMainali-Github
20ac2125a2 tests: prefer max-llvm-major-version over open LLVM ranges 2026-07-29 05:24:17 +00: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
SomeFlyingThing
19c60651fe Optimize slice::contains for bytewise types 2026-07-18 20:23:30 +01: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