Commit Graph

2697 Commits

Author SHA1 Message Date
Folkert de Vries
94cc72682e
implement va_arg for x86_64 systemv and macOS
Turns out LLVM's `va_arg` is also unreliable for this target, so we need
our own implementation.
2025-05-29 22:06:02 +02:00
Folkert de Vries
b2e9c72e72
emit_xtensa_va_arg: use inbounds_ptradd instead of inbounds_gep 2025-05-29 11:21:19 +02:00
Michael Goulet
f0ee1d7100
Rollup merge of #141623 - folkertdev:va-arg-explicit-types, r=workingjubilee
use custom types to clarify arguments to `emit_ptr_va_arg`

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

split out of https://github.com/rust-lang/rust/pull/141622

r? ``@workingjubilee``
``@rustbot`` label: +F-c_variadic
2025-05-27 13:01:43 +02:00
Folkert de Vries
7fe8263285
use custom types to clarify arguments to emit_ptr_va_arg 2025-05-27 01:24:19 +02:00
Noratrieb
fa2bb599bc Cleanup CodegenFnAttrFlags
- Rename `USED` to `USED_COMPILER` to better reflect its behavior.
- Reorder some items to group the used and allocator flags together
- Renumber them without gaps
2025-05-24 20:31:37 +02:00
Stuart Cook
3b22c21dd8
Rollup merge of #140847 - Zalathar:unused-local-file, r=SparrowLii
coverage: Detect unused local file IDs to avoid an LLVM assertion

Each function's coverage metadata contains a *local file table* that maps local file IDs (used by the function's mapping regions) to global file IDs (shared by all functions in the same CGU).

LLVM requires all local file IDs to have at least one mapping region, and has an assertion that will fail if it detects a local file ID with no regions. To make sure that assertion doesn't fire, we need to detect and skip functions whose metadata would trigger it.

(This can't actually happen yet, because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.)
2025-05-19 21:10:42 +10:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
Jieyou Xu
734a5b1aa7
Revert "Fix linking statics on Arm64EC #140176"
Unfortunately, multiple people are reporting linker warnings related to
`__rust_no_alloc_shim_is_unstable` after this change. The solution isn't
quite clear yet, let's revert to green for now, and try a reland with a
determined solution for `__rust_no_alloc_shim_is_unstable`.

This reverts commit c8b7f32434, reversing
changes made to 667247db71.
2025-05-15 16:54:27 +08:00
bors
4eca99a18e Auto merge of #140887 - pietroalbini:pa-bootstrap-update, r=compiler-errors
Stage0 bootstrap update

This PR [follows the release process](https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday) to update the stage0 compiler.

The only thing of note is 58651d1b31, which was flagged by clippy as a correctness fix. I think allowing that lint in our case makes sense, but it's worth to have a second pair of eyes on it.

r? `@Mark-Simulacrum`
2025-05-13 09:54:28 +00:00
bors
1a7f290a9a Auto merge of #140914 - Zalathar:asm-bindings, r=compiler-errors
cg_llvm: Clean up some inline assembly bindings

This PR combines a few loosely-related cleanups to LLVM bindings related to inline assembly. These include:
- Replacing `LLVMRustInlineAsm` with LLVM-C's `LLVMGetInlineAsm`
- Adjusting FFI declarations to avoid the need for explicit `as_c_char_ptr` conversions
- Flattening control flow in `inline_asm_call`

There should be no functional changes.
2025-05-12 17:39:21 +00:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Zalathar
dbdbde2a72 Rename OperandBundleOwned to OperandBundleBox
As with `DIBuilderBox`, the "Box" suffix does a better job of communicating
that this is an owning pointer to some borrowable resource.

This also renames the `raw` method to `as_ref`, which is what it would have
been named originally if the `Deref` problem had been known at the time.
2025-05-11 21:21:38 +10:00
Zalathar
eccf0647d3 Flatten control-flow in inline_asm_call after verification 2025-05-11 14:38:42 +10:00
Zalathar
b6300294a8 Make LLVMRustInlineAsmVerify take *const c_uchar
This avoids the need for an explicit `as_c_char_ptr` conversion.
2025-05-11 14:38:42 +10:00
Zalathar
b1094f6a0a Add a safe wrapper for LLVMAppendModuleInlineAsm
This patch also changes the Rust-side declaration to take `*const c_uchar`
instead of `*const c_char`, to avoid the need for `AsCCharPtr`.
2025-05-11 14:38:42 +10:00
Zalathar
d1bb310a7a Use LLVMGetInlineAsm
This LLVM-C binding replaces the existing `LLVMRustInlineAsm` function.
2025-05-11 14:37:54 +10:00
Zalathar
8764ecd0c1 Add a searchable tag PTR_LEN_STR to explain *const c_uchar bindings
This module comment describes why it's OK for LLVM bindings to declare a
parameter type of `*const c_uchar` for pointer/length strings, even though the
corresponding parameter on the C/C++ side uses `const char *`.

Adding a searchable term to each such parameter should make it easier for
future maintainers to understand why `*const c_uchar` is being used instead of
`*const c_char`.
2025-05-11 14:26:14 +10:00
León Orell Valerian Liehr
3c8950c30d
Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, r=scottmcm,traviscross,tgross35
Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations

This PR creates intrinsics for `{f16,f32,f64,f64}::{minimum,maximum}` operations.

This wasn't done when those operations were added as the LLVM support was too weak but now that LLVM has libcalls for unsupported platforms we can finally use them.

Cranelift and GCC[^1] support are partial, Cranelift doesn't support `f16` and `f128`, while GCC doesn't support `f16`.

r? `@tgross35`

try-job: aarch64-gnu
try-job: dist-various-1
try-job: dist-various-2

[^1]: https://www.gnu.org/software///gnulib/manual/html_node/Functions-in-_003cmath_002eh_003e.html
2025-05-11 02:44:36 +02:00
Urgau
7f0ae5e3ad Use the fallback body for {minimum,maximum}f128 on LLVM as well. 2025-05-10 17:34:54 +02:00
Matthias Krüger
b8c55b438d
Rollup merge of #140660 - RalfJung:more-order, r=WaffleLapkin
remove 'unordered' atomic intrinsics

As their doc comment already indicates, these operations do not currently have a place in our memory model. The intrinsics were introduced to support a hack in compiler-builtins, but that hack recently got removed (see https://github.com/rust-lang/compiler-builtins/issues/788).
2025-05-10 16:26:02 +02:00
mejrs
684b7b70f4 don't depend on rustc_attr_parsing if rustc_data_structures will do 2025-05-09 23:16:55 +02:00
Ralf Jung
79dfd0a472 remove 'unordered' atomic intrinsics 2025-05-09 17:39:52 +02:00
Urgau
e7247df590 Use intrinsics for {f16,f32,f64,f128}::{minimum,maximum} operations 2025-05-09 17:11:23 +02:00
Zalathar
078144fdfa coverage: Detect unused local file IDs to avoid an LLVM assertion
This case can't actually happen yet (other than via a testing flag), because
currently all of a function's spans must belong to the same file and expansion.
But this will be an important edge case when adding expansion region support.
2025-05-10 00:24:03 +10:00
Zalathar
8cd8b23b9e coverage: Hoist counter_for_bcb out of its loop
Having this helper function in the loop was confusing, because it doesn't rely
on anything that changes between loop iterations.
2025-05-10 00:24:03 +10:00
Zalathar
339556eb02 coverage: Enlarge empty spans during MIR instrumentation, not codegen
This allows us to assume that coverage spans will only be discarded during
codegen in very unusual situations.
2025-05-10 00:24:01 +10:00
bors
c8b7f32434 Auto merge of #140176 - dpaoliello:arm64ecdec, r=wesleywiser
Fix linking statics on Arm64EC

Arm64EC builds recently started to fail due to the linker not finding a symbol:
```
symbols.o : error LNK2001: unresolved external symbol #_ZN3std9panicking11EMPTY_PANIC17hc8d2b903527827f1E (EC Symbol)
          C:\Code\hello-world\target\arm64ec-pc-windows-msvc\debug\deps\hello_world.exe : fatal error LNK1120: 1 unresolved externals
```

It turns out that `EMPTY_PANIC` is a new static variable that was being exported then imported from the standard library, but when exporting LLVM didn't prepend the name with `#` (as only functions are prefixed with this character), whereas Rust was prefixing with `#` when attempting to import it.

The fix is to have Rust not prefix statics with `#` when importing.

Adding tests discovered another issue: we need to correctly mark static exported from dylibs with `DATA`, otherwise MSVC's linker assumes they are functions and complains that there is no exit thunk for them.

CI found another bug: we only apply `DllImport` to non-local statics that aren't foreign items (i.e., in an `extern` block), that is we want to use `DllImport` for statics coming from other Rust crates. However, `__rust_no_alloc_shim_is_unstable` is a static generated by the Rust compiler if required, but downstream crates consider it a foreign item since it is declared in an `extern "Rust"` block, thus they do not apply `DllImport` to it and so fails to link if it is exported by the previous crate as `DATA`. The fix is to apply `DllImport` to foreign items that are marked with the `rustc_std_internal_symbol` attribute (i.e., we assume they aren't actually foreign and will be in some Rust crate).

Fixes #138541

---
try-job: dist-aarch64-msvc
try-job: dist-x86_64-msvc
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
2025-05-09 00:43:28 +00:00
Daniel Paoliello
6dabf7ea3a [Arm64EC] Only decorate functions with # 2025-05-07 10:36:12 -07:00
Jacob Pratt
4a8dbe0537
Rollup merge of #139534 - madhav-madhusoodanan:apx-target-feature-addition, r=workingjubilee
Added support for `apxf` target feature
2025-05-07 00:29:21 +00:00
Madhav Madhusoodanan
43357b4a64 Added apxf target feature support, under flag apx_target_feature 2025-05-06 23:28:27 +05:30
Michael Goulet
833c212b81 Rename Instance::new to Instance::new_raw and add a note that it is raw 2025-05-05 13:17:35 +00:00
Madhav Madhusoodanan
e4272d12f2 feat: Added capability to add multiple dependencies for an LLVMFeature 2025-05-05 12:33:37 +05:30
Bryanskiy
14535312b5 Initial support for dynamically linked crates 2025-05-04 22:03:15 +03:00
Stuart Cook
ed7590f1a0
Rollup merge of #139675 - sayantn:avx10, r=Amanieu
Add the AVX10 target features

Parent #138843

Adds the `avx10_target_feature` feature gate, and `avx10.1` and `avx10.2` target features.

It is confirmed that Intel is dropping AVX10/256 (see [this comment](https://github.com/rust-lang/rust/issues/111137#issuecomment-2795442288)), so this should be safe to implement now.

The LLVM fix for llvm/llvm-project#135394 was merged, and has been backported to LLVM20, and the patch has also been propagated to rustc in #140502

`@rustbot` label O-x86_64 O-x86_32 A-target-feature A-SIMD
2025-05-04 13:21:07 +10:00
Guillaume Gomez
9d7d782e50
Rollup merge of #140460 - heiher:issue-140455, r=Urgau
Fix handling of LoongArch target features not supported by LLVM 19

Fixes #140455
2025-05-01 22:27:23 +02:00
Matthias Krüger
555df301f8
Rollup merge of #134232 - bjorn3:naked_asm_improvements, r=wesleywiser
Share the naked asm impl between cg_ssa and cg_clif

This was introduced in https://github.com/rust-lang/rust/pull/128004.
2025-04-30 17:27:57 +02:00
WANG Rui
a2b3f11700 Filter out LoongArch features not supported by the current LLVM version 2025-04-29 22:12:27 +08:00
Trevor Gross
19e82b43eb Enable target_has_reliable_f16_math on x86
This has been disabled due to an LLVM misoptimization with `powi.f16`
[1]. This was fixed upstream and the fix is included in LLVM20, so tests
no longer need to be disabled.

`f16` still remains disabled on MinGW due to the ABI issue.

[1]: https://github.com/llvm/llvm-project/issues/98665
2025-04-29 05:39:15 +00:00
Chris Denton
e082bf341f
Rollup merge of #140323 - tgross35:cfg-unstable-float, r=Urgau
Implement the internal feature `cfg_target_has_reliable_f16_f128`

Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for the type works correctly. The `_math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for `std` tests and `compiler-builtins` that don't have any way to configure based on the codegen backend.

MCP: https://github.com/rust-lang/compiler-team/issues/866
Closes: https://github.com/rust-lang/compiler-team/issues/866

[1]: 555e1d0386/library/std/build.rs (L84-L186)

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
2025-04-28 23:29:17 +00:00
Chris Denton
d4845e1b0b
Rollup merge of #139308 - Shourya742:2025-03-29-add-autodiff-inline, r=ZuseZ4
add autodiff inline

closes: #138920

r? ```@ZuseZ4```

try-job: dist-aarch64-linux
2025-04-28 23:29:14 +00:00
bit-aloo
7018392337
remove noinline attribute and add alwaysinline after AD pass 2025-04-28 21:10:32 +05:30
Andrew Zhogin
c366756a85 AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
Trevor Gross
6ceeb0849e Implement the internal feature cfg_target_has_reliable_f16_f128
Support for `f16` and `f128` is varied across targets, backends, and
backend versions. Eventually we would like to reach a point where all
backends support these approximately equally, but until then we have to
work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which
provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for
the type works correctly. The `_math` versions indicate that anything
relying on `libm` works correctly, since sometimes this hits a separate
class of codegen bugs.

These options match configuration set by the build script at [1]. The
logic for LLVM support is duplicated as-is from the same script. There
are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is
only intended to replace the build scripts for `std` tests and
`compiler-builtins` that don't have any way to configure based on the
codegen backend.

MCP: https://github.com/rust-lang/compiler-team/issues/866
Closes: https://github.com/rust-lang/compiler-team/issues/866

[1]: 555e1d0386/library/std/build.rs (L84-L186)
2025-04-27 19:58:44 +00:00
sayantn
163fb854a2
Add the avx10.1 and avx10.2 target features 2025-04-26 11:40:13 +05:30
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
bit-aloo
9bc04016e6
add custom enzyme markers to target methods 2025-04-25 11:09:52 +05:30
bit-aloo
f319dd909e
add llvm wrappers and corresponding methods in attribute 2025-04-25 11:09:52 +05:30
Matthias Krüger
c3f811f02f
Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk
Autodiff flags

Interestingly, it seems that some other projects have conflicts with exactly the same LLVM optimization passes as autodiff.
At least `LLVMRustOptimize` has exactly the flags that we need to disable problematic opt passes.

This PR enables us to compile code where users differentiate two identical functions in the same module. This has been especially common in test cases, but it's not impossible to encounter in the wild.

It also enables two new flags for testing/debugging. I consider writing an MCP to upgrade PrintPasses to be a standalone -Z flag, since it is *not* the same as `-Z print-llvm-passes`, which IMHO gives less useful output. A discussion can be found here: [#t-compiler/llvm > Print llvm passes. @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/Print.20llvm.20passes.2E/near/511533038)

Finally, it improves `PrintModBefore` and `PrintModAfter`. They used to work reliable, but now we just schedule enzyme as part of an existing ModulePassManager (MPM). Since Enzyme is last in the MPM scheduling, PrintModBefore became very inaccurate. It used to print the input module, which we gave to the Enzyme and was great to create llvm-ir reproducer. However, lately the MPM would run the whole `default<O3>` pipeline, which heavily modifies the llvm module, before we pass it to Enzyme. That made it impossible to use the flag to create llvm-ir reproducers for Enzyme bugs. We now schedule a PrintModule pass just before Enzyme, solving this problem.

Based on the PrintPass output, it also _seems_ like changing `registerEnzymeAndPassPipeline(PB, true);` to `registerEnzymeAndPassPipeline(PB, false);` has no effect. In theory, the bool should tell Enzyme to schedule some helpful passes in the PassBuilder. However, since it doesn't do anything and I'm not 100% sure anymore on whether we really need it, I'll just disable it for now and postpone investigations.

r? ``@oli-obk``

closes #139471

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-24 17:19:44 +02:00
Matthias Krüger
a8ebfb256a
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
mitigate MSVC alignment issue on x86-32

This implements mitigation for https://github.com/rust-lang/rust/issues/112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems.

Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can.

Also add an errata note to the platform support page warning users about this known problem.

try-job: `i686-msvc*`
2025-04-24 11:40:35 +02:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00