Commit Graph

3816 Commits

Author SHA1 Message Date
Folkert de Vries 7787bd915b fix macho section specifier & windows test 2026-04-16 11:37:46 +02:00
Folkert de Vries bc4aad37ca naked-functions: properly document the -Zfunction-sections windows status 2026-04-16 11:37:45 +02:00
Folkert de Vries 872301bfdd naked functions: respect function_sections on linux/macos 2026-04-16 11:37:45 +02:00
Folkert de Vries 0e522d6c62 naked functions: respect function_sections on windows
For `gnu` function_sections is off by default.
2026-04-16 11:37:45 +02:00
Jacob Pratt 803a7227fb Rollup merge of #155005 - folkertdev:simd-element-type-llvm, r=nnethercote
preserve SIMD element type information

Preserve the SIMD element type and provide it to LLVM for better optimization.

This is relevant for AArch64 types like `int16x4x2_t`, see also https://github.com/llvm/llvm-project/issues/181514. Such types are defined like so:

```rust
#[repr(simd)]
struct int16x4_t([i16; 4]);

#[repr(C)]
struct int16x4x2_t(pub int16x4_t, pub int16x4_t);
```

Previously this would be translated to the opaque `[2 x <8 x i8>]`, with this PR it is instead `[2 x <4 x i16>]`. That change is not relevant for the ABI, but using the correct type prevents bitcasts that can (indeed, do) confuse the LLVM pattern matcher.

This change will make it possible to implement the deinterleaving loads on AArch64 in a portable way (without neon-specific intrinsics), which means that e.g. Miri or the cranelift backend can run them without additional support.

discussion at [#t-compiler > loss of vector element type information](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/loss.20of.20vector.20element.20type.20information/with/584483611)
2026-04-14 00:37:24 -04:00
bors 338dff3e3a Auto merge of #136006 - oli-obk:push-tzonluoyuwkq, r=wesleywiser
Start using pattern types in libcore



cc rust-lang/rust#135996

Replaces the innards of `NonNull` with `*const T is !null`.

This does affect LLVM's optimizations, as now reading the field preserves the metadata that the field is not null, and transmuting to another type (e.g. just a raw pointer), will also preserve that information for optimizations. This can cause LLVM opts to do more work, but it's not guaranteed to produce better machine code.

Once we also remove all uses of rustc_layout_scalar_range_start from rustc itself, we can remove the support for that attribute entirely and handle all such needs via pattern types
2026-04-13 21:54:46 +00:00
bors 17584a1819 Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
Oli Scherer 834137afd7 Use !null pattern type in libcore 2026-04-13 17:23:03 +02:00
Folkert de Vries 6f428df8df preseve SIMD element type information
and provide it to LLVM for better optimization
2026-04-13 13:26:50 +02:00
David Wood da948999eb cg_ssa: transmute between scalable vectors
Like regular SIMD vectors, we can support casting between scalable
vectors of integral or floating-point types without needing a temporary.
2026-04-13 04:24:28 +00:00
David Wood ca6a85155b cg_llvm: replace sve_cast with simd_cast
Previously `sve_cast`'s implementation was abstracted to power both
`sve_cast` and `simd_cast` which supported scalable and non-scalable
vectors respectively. In anticipation of having to do this for another
`simd_*` intrinsic, `sve_cast` is removed and `simd_cast` is changed to
accept both scalable and non-scalable intrinsics, an approach that will
scale better to the other intrinsics.
2026-04-13 01:57:55 +00:00
Jonathan Brouwer 197fb1b0d7 Rollup merge of #154449 - nnethercote:rustc_errors-dep-rustc_abi, r=davidtwco
Invert dependency between `rustc_errors` and `rustc_abi`.

Currently, `rustc_errors` depends on `rustc_abi`, which depends on `rustc_error_messages`. This is a bit odd.

`rustc_errors` depends on `rustc_abi` for a single reason: `rustc_abi` defines a type `TargetDataLayoutErrors` and `rustc_errors` impls `Diagnostic` for that type.

We can get a more natural relationship by inverting the dependency, moving the `Diagnostic` trait upstream. Then `rustc_abi` defines `TargetDataLayoutErrors` and also impls `Diagnostic` for it. `rustc_errors` is already pretty far upstream in the crate graph, it doesn't hurt to push it a little further because errors are a very low-level concept.

r? @davidtwco
2026-04-10 18:38:13 +02:00
Jacob Pratt 5a6abf3425 Rollup merge of #154677 - Darksonn:hwasan-tagged-globals, r=davidtwco
hwaddress: automatically add `-Ctarget-feature=+tagged-globals`

Note that since HWAddressSanitizer is/should be a target modifier, we do not have to worry about whether this LLVM target feature changes the ABI.

Fixes: rust-lang/rust#148185
2026-04-09 23:59:59 -04:00
Jacob Pratt 827c27d39a Rollup merge of #154856 - bjorn3:fix_dylib_profiler_builtins, r=mati865
Fix linking two dylibs together when both depend on profiler_builtins

See the comment inside this commit for why.

Fixes a regression from https://github.com/rust-lang/rust/pull/150014 reported at [#t-compiler > 1.94 profiler_builtin linkage in dylibs](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/1.2E94.20profiler_builtin.20linkage.20in.20dylibs/with/583704962).
2026-04-08 23:03:57 -04:00
Jonathan Brouwer b040d5493e Rollup merge of #154598 - folkertdev:windows-naked-link-section, r=mati865
test `#[naked]` with `#[link_section = "..."]` on windows

As a part of https://github.com/rust-lang/rust/pull/147811 I ran into that we actually don't match (current) LLVM output.

r? @mati865
2026-04-08 23:04:33 +02:00
Nicholas Nethercote 3ff4201fd1 Move rustc_middle::mir::mono to rustc_middle::mono
Because the things in this module aren't MIR and don't use anything
from `rustc_middle::mir`. Also, modules that use `mono` often don't use
anything else from `rustc_middle::mir`.
2026-04-07 08:33:54 +10:00
Folkert de Vries 72b6825828 test #[naked] with #[link_section = "..."] on windows 2026-04-06 14:58:52 +02:00
bors 5a0d572cd1 Auto merge of #154870 - JonathanBrouwer:rollup-OFrhW8F, r=JonathanBrouwer
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#153440 (Various LTO cleanups)
 - rust-lang/rust#151899 (Constify fold, reduce and last for iterator)
 - rust-lang/rust#154561 (Suggest similar keyword when visibility is not followed by an item)
 - rust-lang/rust#154657 (Fix pattern assignment suggestions for uninitialized bindings)
 - rust-lang/rust#154717 (Fix ICE in unsafe binder discriminant helpers)
 - rust-lang/rust#154722 (fix(lints): Improve `ill_formed_attribute_input` with better help message)
 - rust-lang/rust#154777 (`#[cfg]`: suggest alternative `target_` name when the value does not match)
 - rust-lang/rust#154849 (Promote `char::is_case_ignorable` from perma-unstable to unstable)
 - rust-lang/rust#154850 (ast_validation: scalable vectors okay for rustdoc)
2026-04-06 06:45:42 +00:00
Jonathan Brouwer 5f8b82805e Rollup merge of #153440 - bjorn3:lto_refactors13, r=TaKO8Ki
Various LTO cleanups

* Move some special casing of thin local LTO into a single location.
* Move lto_import_only_modules handling for fat LTO earlier. There is no reason to keep it separate until right before pass the LTO modules to the codegen backend. For thin LTO this introduces `ThinLtoInput` to correctly handle incr comp caching.
* Remove the `Linker` type from cg_llvm. It previously helped deduplicate code for `-Zcombine-cgus`, but that flag no longer exists.

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-04-06 08:27:49 +02:00
Jacob Pratt 24223a62ae Rollup merge of #154744 - nnethercote:rm-Clone-for-StableHashingContext, r=fee1-dead
Remove `Clone` impl for `StableHashingContext`.

`HashStable::hash_stable` takes a `&mut Hcx`. In contrast, `ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are some places where the latter calls the former, and due to the mismatch a `clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`. This eliminates the mismatch, the need for the clones, and the need for the `Clone` impls.

r? @fee1-dead
2026-04-05 20:51:06 -04:00
bjorn3 642f348805 Fix linking two dylibs together when both depend on profiler_builtins
See the comment inside this commit for why.
2026-04-05 20:24:31 +02:00
David Wood a24ee0329e cg_llvm/debuginfo: scalable vectors
Generate debuginfo for scalable vectors, following the structure that
Clang generates for scalable vectors.
2026-04-03 10:37:42 +00:00
David Wood a2f7f3c1eb ty_utils: lower tuples to ScalableVector repr
Instead of just using regular struct lowering for these types, which
results in an incorrect ABI (e.g. returning indirectly), use
`BackendRepr::ScalableVector` which will lower to the correct type and
be passed in registers.

This also enables some simplifications for generating alloca of scalable
vectors and greater re-use of `scalable_vector_parts`.

A LLVM codegen test demonstrating the changed IR this generates is
included in the next commit alongside some intrinsics that make these
tuples usable.
2026-04-03 10:27:30 +00:00
Nicholas Nethercote ff1795fe49 Remove Clone impl for StableHashingContext.
`HashStable::hash_stable` takes a `&mut Hcx`. In contrast,
`ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are
some places where the latter calls the former, and due to the mismatch a
`clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`.
This eliminates the mismatch, the need for the clones, and the need for
the `Clone` impls.
2026-04-03 15:34:33 +11:00
Wesley Wiser c9d3a00cd1 Revert "Fix: On wasm targets, call panic_in_cleanup if panic occurs in cleanup"
This reverts commit acbfd79acf.
2026-04-01 21:29:42 -05:00
bjorn3 3303a26a2e Slightly improve comment in produce_final_output_artifacts
It is still not entirely correct I think, but much
closer to the current way things are done.
2026-04-01 14:14:23 +00:00
bjorn3 ed16e62542 Introduce ThinLtoInput 2026-04-01 14:14:23 +00:00
bjorn3 cee57cc2fa Handle lto_import_only_modules for fat LTO earlier 2026-04-01 14:14:23 +00:00
bjorn3 e70561b8ac Move some thin local LTO handling to start_executing_work
By not pushing any crates to each_linked_rlib_for_lto when no
cross-crate LTO is used, we can avoid special cases elsewhere.
2026-04-01 14:14:23 +00:00
Alice Ryhl 6fc3880b04 hwaddress: automatically add -Ctarget-feature=tagged-globals 2026-04-01 12:38:55 +00:00
Jonathan Brouwer 3cef5b54bc Rollup merge of #154634 - nnethercote:hcx, r=petrochenkov
Use `Hcx`/`hcx` consistently for `StableHashingContext`.

The `HashStable` and `ToStableHashKey` traits both have a type parameter that is sometimes called `CTX` and sometimes called `HCX`. (In practice this type parameter is always instantiated as `StableHashingContext`.) Similarly, variables with these types are sometimes called `ctx` and sometimes called `hcx`. This inconsistency has bugged me for some time.

The `HCX`/`hcx` form is more informative (the `H`/`h` indicates what type of context it is) and it matches other cases like `tcx`, `dcx`, `icx`.

Also, RFC 430 says that type parameters should have names that are "concise UpperCamelCase, usually single uppercase letter: T". In this case `H` feels insufficient, and `Hcx` feels better.

Therefore, this commit changes the code to use `Hcx`/`hcx` everywhere.

r? @petrochenkov
2026-03-31 15:27:19 +02:00
Nicholas Nethercote ccc3c01162 Use Hcx/hcx consistently for StableHashingContext.
The `HashStable` and `ToStableHashKey` traits both have a type parameter
that is sometimes called `CTX` and sometimes called `HCX`. (In practice
this type parameter is always instantiated as `StableHashingContext`.)
Similarly, variables with these types are sometimes called `ctx` and
sometimes called `hcx`. This inconsistency has bugged me for some time.

The `HCX`/`hcx` form is more informative (the `H`/`h` indicates what
type of context it is) and it matches other cases like `tcx`, `dcx`,
`icx`.

Also, RFC 430 says that type parameters should have names that are
"concise UpperCamelCase, usually single uppercase letter: T". In this
case `H` feels insufficient, and `Hcx` feels better.

Therefore, this commit changes the code to use `Hcx`/`hcx` everywhere.
2026-03-31 20:16:57 +11:00
Trevor Gross 4b2378286c Rollup merge of #153648 - AsakuraMizu:fix-eii-lto-alias, r=jdonszelmann,bjorn3
Fix EII function aliases eliminated by LTO

Add EII function aliases to `llvm.compiler.used` so that LLVM's LTO passes do not eliminate them.

Fixes rust-lang/rust#153645

Tracking issue: https://github.com/rust-lang/rust/issues/125418
2026-03-31 05:08:24 -04:00
Nicholas Nethercote 0db4e3a883 De-pluralize the names of two error enums.
Error enum names should not be plural. Even though there are multiple
possible errors, each instance of an error enum describes a single
error. There are dozens of singular error enum names, and only two
plural error enum names. This commit makes them both singular.
2026-03-30 14:15:44 +11:00
Guillaume Gomez e6f17e4bbb Rollup merge of #153834 - N1ark:generic-float-intrinsics, r=tgross35,RalfJung
Merge `fabsf16/32/64/128` into `fabs::<F>`

Following [a small conversation on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Float.20intrinsics/with/521501401) (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :)

This PR just merges `fabsf16`, `fabsf32`, `fabsf64`, `fabsf128`, as it felt like an easy first target.

Notes:
- I'm opening the PR for one intrinsic as it's probably easier if the shift is done one intrinsic at a time, but let me know if you'd rather I do several at a time to reduce the number of PRs.
- Currently this PR increases LOCs, despite being an attempt at simplifying the intrinsics/compilers. I believe this increase is a one time thing as I had to define new functions and move some things around, and hopefully future PRs/commits will reduce overall LoCs
- `fabsf32` and `fabsf64` are `#[rustc_intrinsic_const_stable_indirect]`, while `fabsf16` and `fabsf128` aren't; because `f32`/`f64` expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch is `minnum`, `maxnum` and `copysign`.
- I haven't touched libm because I'm not familiar with how it works; any guidance would be welcome!
2026-03-29 00:06:50 +01:00
Jacob Pratt 433e106dd2 Rollup merge of #152457 - pmur:murp/mcount-link-pg, r=davidtwco
Pass -pg to linker when using -Zinstrument-mcount

This selects a slightly different crt on gnu targets which enables the profiler within glibc.

This makes using gprof a little easier with Rust binaries. Otherwise, rustc must be passed `-Clink-args=-pg` to ensure the correct startup code is linked.
2026-03-27 02:30:06 -04:00
Jonathan Brouwer 6e6e266520 Rollup merge of #153857 - RalfJung:cfg-abi, r=Mark-Simulacrum
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname

See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in https://github.com/rust-lang/rust/pull/153769#discussion_r2934399038 too.

This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI).

Also turn llvm_abiname into an enum to make it more natural to match on.
Cc @workingjubilee @madsmtm
2026-03-23 12:14:54 +01:00
Ralf Jung 6b1487698c enum-ify llvm_abiname 2026-03-22 10:34:32 +01:00
Ralf Jung 40ebcc031d target specs: rename abi to cfg_abi 2026-03-22 10:34:32 +01:00
teor 55d9f7cb6c Fix typos and outdated comments 2026-03-20 11:22:53 +10:00
Stuart Cook c0172a38cd Rollup merge of #153580 - mati865:elf-raw-dylib-static-and-tls, r=bjorn3
Handle statics and TLS in raw-dylib for ELF

Follow-up to https://github.com/rust-lang/rust/pull/153090
2026-03-18 21:26:32 +11:00
Mateusz Mikuła ed4afa5989 Set symbols value in raw-dylib for ELF
With this change LLD finally produces working binaries with static
relocation model.
2026-03-17 21:29:11 +01:00
Mateusz Mikuła 36381555bb Put statics in .data section in raw-dylib for ELF
This fixes issues with statics when using static relocation model and
linking with GNU ld. Other linkers don't work yet.
2026-03-17 21:25:32 +01:00
Mateusz Mikuła f3654324e6 Set symbol size in raw-dylib for ELF 2026-03-17 21:23:16 +01:00
Mateusz Mikuła 82727b0c0f Refactor DllImport to better differentiate types 2026-03-17 21:21:25 +01:00
Jonathan Brouwer f4cc98ae79 Rollup merge of #153920 - folkertdev:track-caller-abi-error, r=JonathanBrouwer
improve `#[track_caller]` invalid ABI error

Niche but we can provide more context by emitting the error earlier.
2026-03-17 17:51:34 +01:00
N1ark 11c673b405 Remove InvalidMonomorphization::FloatingPointType 2026-03-16 21:49:06 +00:00
Folkert de Vries cd4fd289cd suggest valid features when target feature is invalid 2026-03-16 17:44:16 +01:00
Folkert de Vries 461038f0c9 improve #[track_caller] invalid ABI error 2026-03-15 17:17:36 +01:00
Stuart Cook 59f98f0e3d Rollup merge of #153769 - RalfJung:target-spec-abi-checks, r=madsmtm
target specs: stricter checks for LLVM ABI values, and correlate that with cfg(target_abi)

This tightens the checks for `llvm_abiname`, `llvm_floatabi` and `rustc_abi` in our target specs. Those are the fields that actually control the ccABI. With this commit, we now have an allowlist of value for these fields for all architectures (we previously only had that for some architectures). We also check that `cfg(target_abi)` suitably correlates with the actual ccABI. I based this check on our in-tree targets. For all ccABIs where we had a bunch of "random" values that don't directly correlate to the ccABI (like "uwp"), I also allowed  `cfg(target_abi)`  to remain empty, and whenever it is allowed to be empty I also allowed arbitrary other values for JSON targets. However, there's still a risk that JSON targets will fail this new check -- the idea is that we'll then get bugreports and can adjust the check as needed.

I had to adjust the target specs for non-ARM32 Apple targets as those were all setting `llvm_floatabi`, which to my knowledge makes no sense -- LLVM only actually does anything with that field on ARM32. I also adjusted the target specs for MIPS32 targets: one of them was setting llvm_abiname, and then it seems safer and more consistent to set that for all targets, so I set it to "o32" everywhere which seems to be the default.

Cc @workingjubilee
2026-03-14 23:30:10 +11:00