about summary refs log tree commit diff
path: root/tests/codegen-llvm
AgeCommit message (Collapse)AuthorLines
2025-09-03Add amdgpu to gpu-kernel testFlakebi-1/+4
Check that the gpu-kernel calling convention translates to `amdgpu_kernel` when compiling for the amdgpu target.
2025-09-03Add test for addrspacecasting global varsFlakebi-0/+9
Global variables are casted to the default address space works, as the amdgpu target is now merged, a test can be added.
2025-09-03explicitly start `va_list` lifetimeFolkert de Vries-0/+21
2025-09-02Rollup merge of #146116 - zmodem:issue_118306_fix, r=nikicGuillaume Gomez-1/+1
Adjust issue-118306.rs test after LLVM change This updates tests/codegen-llvm/issues/issue-118306.rs to pass also after https://github.com/llvm/llvm-project/pull/155415
2025-09-02Rollup merge of #144066 - RalfJung:extern-c-variadics, r=workingjubileeGuillaume Gomez-1/+1
stabilize c-style varargs for sysv64, win64, efiapi, aapcs This has been split up so the PR now only contains the extended_varargs_abi_support stabilization; "system" has been moved to https://github.com/rust-lang/rust/pull/145954. **Previous (combined) PR description:** This stabilizes extern block declarations of variadic functions with the system, sysv64, win64, efiapi, aapcs ABIs. This corresponds to the extended_varargs_abi_support and extern_system_varargs feature gates. The feature gates were split up since it seemed like there might be further discussion needed for what exactly "system" ABI variadic functions should do, but a [consensus](https://github.com/rust-lang/rust/issues/136946#issuecomment-2967847553) has meanwhile been reached: they shall behave like "C" functions. IOW, the ABI of a "system" function is (bold part is new in this PR): - "stdcall" for win32 targets **for non-variadic functions** - "C" for everything else This had been previously stabilized *without FCP* in https://github.com/rust-lang/rust/pull/116161, which got reverted in https://github.com/rust-lang/rust/pull/136897. There was also a "fun" race condition involved with the system ABI being [added](https://github.com/rust-lang/rust/pull/119587) to the list of variadic-supporting ABIs between the creation and merge of rust-lang/rust#116161. There was a question raised [here](https://github.com/rust-lang/rust/pull/116161#issuecomment-1983829513) whether t-lang even needs to be involved for a change like this. Not sure if that has meanwhile been clarified? The behavior of the "system" ABI (a Rust-specific ABI) definitely feels like t-lang territory to me. Fixes rust-lang/rust#100189 Cc `@rust-lang/lang` # Stabilization report > ## General design > ### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized? AFAIK there is no RFC. The tracking issues are - https://github.com/rust-lang/rust/issues/100189 - https://github.com/rust-lang/rust/issues/136946 > ### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con. The only controversial point is whether "system" ABI functions should support variadics. - Pro: This allows crates like windows-rs to consistently use "system", see e.g. https://github.com/microsoft/windows-rs/issues/3626. - Cons: `@workingjubilee` had some implementation concerns, but I think those have been [resolved](https://github.com/rust-lang/rust/issues/136946#issuecomment-2967847553). EDIT: turns out Jubilee still has concerns (she mentioned that in a DM); I'll let her express those. Note that "system" is already a magic ABI we introduced to "do the right thing". This just makes it do the right thing in more cases. In particular, it means that on Windows one can almost always just do ```rust extern "system" { // put all the things here } ``` and it'll do the right thing, rather than having to split imports into non-varargs and varargs, with the varargs in a separate `extern "C"` block (and risking accidentally putting a non-vararg there). (I am saying "almost" always because some Windows API functions actually use cdecl, not stdcall, on x86. Those of course need to go in `extern "C"` blocks.) > ### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those? Actually defining variadic functions in Rust remains unstable, under the [c_variadic feature gate](https://github.com/rust-lang/rust/issues/44930). > ## Has a Call for Testing period been conducted? If so, what feedback was received? > > Does any OSS nightly users use this feature? For instance, a useful indication might be "search <grep.app> for `#![feature(FEATURE_NAME)]` and had `N` results". There was no call for testing. A search brings up https://github.com/rust-osdev/uefi-rs/blob/main/uefi-raw/src/table/boot.rs using this for "efiapi". This doesn't seem widely used, but it is an "obvious" gap in our support for c-variadics. > ## Implementation quality All rustc does here is forward the ABI to LLVM so there's lot a lot to say here... > ### Summarize the major parts of the implementation and provide links into the code (or to PRs) > > An example for async closures: <https://rustc-dev-guide.rust-lang.org/coroutine-closures.html>. The check for allowed variadic ABIs is [here](https://github.com/rust-lang/rust/blob/9c870d30e2d6434c9e9a004b450c5ccffdf3d844/compiler/rustc_hir_analysis/src/lib.rs#L109-L126). The special handling of "system" is [here](https://github.com/rust-lang/rust/blob/c24914ec8329b22ec7bcaa6ab534a784b2bd8ab9/compiler/rustc_target/src/spec/abi_map.rs#L82-L85). > ### Summarize existing test coverage of this feature > > Consider what the "edges" of this feature are. We're particularly interested in seeing tests that assure us about exactly what nearby things we're not stabilizing. > > Within each test, include a comment at the top describing the purpose of the test and what set of invariants it intends to demonstrate. This is a great help to those reviewing the tests at stabilization time. > > - What does the test coverage landscape for this feature look like? > - Tests for compiler errors when you use the feature wrongly or make mistakes? > - Tests for the feature itself: > - Limits of the feature (so failing compilation) > - Exercises of edge cases of the feature > - Tests that checks the feature works as expected (where applicable, `//@ run-pass`). > - Are there any intentional gaps in test coverage? > > Link to test folders or individual tests (ui/codegen/assembly/run-make tests, etc.). Prior PRs add a codegen test for all ABIs and tests actually calling extern variadic functions for sysv64 and win64: - https://github.com/rust-lang/rust/pull/144359 - https://github.com/rust-lang/rust/pull/144379 We don't have a way of executing uefi target code in the test suite, so it's unclear how to fully test efiapi. aapcs could probably be done? (But note that we have hardly an such actually-calling-functions tests for ABI things, we almost entirely rely on codegen tests.) The test ensuring that we do *not* stabilize *defining* c-variadic functions is `tests/ui/feature-gates/feature-gate-c_variadic.rs`. > ### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking? None that I am aware of. > ### What FIXMEs are still in the code for that feature and why is it ok to leave them there? None that I am aware of. > ### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization `@Soveu` added sysv64, win64, efiapi, aapcs to the list of ABIs that allow variadics, `@beepster4096` added system. `@workingjubilee` recently refactored the ABI handling in the compiler, also affecting this feature. > ### Which tools need to be adjusted to support this feature. Has this work been done? > > Consider rustdoc, clippy, rust-analyzer, rustfmt, rustup, docs.rs. Maybe RA needs to be taught about the new allowed ABIs? No idea how precisely they mirror what exactly rustc accepts and rejects here. > ## Type system and execution rules > ### What compilation-time checks are done that are needed to prevent undefined behavior? > > (Be sure to link to tests demonstrating that these tests are being done.) Nothing new here, this just expands the existing support for calling variadic functions to more ABIs. > ### Does the feature's implementation need checks to prevent UB or is it sound by default and needs opt in in places to perform the dangerous/unsafe operations? If it is not sound by default, what is the rationale? Nothing new here, this just expands the existing support for calling variadic functions to more ABIs. > ### Can users use this feature to introduce undefined behavior, or use this feature to break the abstraction of Rust and expose the underlying assembly-level implementation? (Describe.) Nothing new here, this just expands the existing support for calling variadic functions to more ABIs. > ### What updates are needed to the reference/specification? (link to PRs when they exist) - https://github.com/rust-lang/reference/pull/1936 > ## Common interactions > ### Does this feature introduce new expressions and can they produce temporaries? What are the lifetimes of those temporaries? No. > ### What other unstable features may be exposed by this feature? None.
2025-09-02Adjust issue-118306.rs test after LLVM changeHans Wennborg-1/+1
This updates tests/codegen-llvm/issues/issue-118306.rs to pass also after https://github.com/llvm/llvm-project/pull/155415
2025-09-02stabilize extended_varargs_abi_supportRalf Jung-1/+1
2025-09-01Auto merge of #143290 - azhogin:azhogin/link-pub-async-impls, r=oli-obkbors-4/+4
pub async fn impl is monomorphized when func itself is monomorphized Implentation coroutine (`func::{closure#0}`) is monomorphized, when func itself is monomorphized. Currently, when `pub async fn foo(..)` is exported from lib and used in several dependent crates, only 'header' function is monomorphized in the defining crate. 'header' function, returning coroutine object, is monomorphized, but the coroutine's poll function (which actually implements all the logic for the function) is not. In such situation, `func::{closure#0}` will be monomorphized in every dependency. This PR adds monomorphization for `func::{closure#0}` (coroutine poll function), when func itself is monomorphized. Simple test with one lib async function and ten dependent crates (executable) that use the function, shows 5-7% compilation time improvement (single-threaded).
2025-09-01pub async fn implementation coroutine (func::{closure#0}) is monomorphized, ↵Andrew Zhogin-4/+4
when func itself is monomorphized
2025-08-30Rollup merge of #145465 - Kivooeo:stabilize-array_repeat, r=joboetStuart Cook-2/+0
Stabilize `array_repeat` feature This closes [tracking issue](https://github.com/rust-lang/rust/issues/126695) and stabilises `array::repeat`
2025-08-29Rollup merge of #145467 - Kivooeo:stabilize-strict_provenance_atomic_ptr, ↵Trevor Gross-1/+0
r=scottmcm Stabilize `strict_provenance_atomic_ptr` feature This closes [tracking issue](https://github.com/rust-lang/rust/issues/99108) and stabilises `AtomicPtr::{fetch_ptr_add, fetch_ptr_sub, fetch_byte_add, fetch_byte_sub, fetch_or, fetch_and, fetch_xor}` --- EDIT: FCP completed at https://github.com/rust-lang/rust/issues/99108#issuecomment-3168260347
2025-08-26Use captures(address) instead of captures(none) for indirect argsNikita Popov-7/+7
While provenance cannot be captured through these arguments, the address / object identity can.
2025-08-22Rollup merge of #145380 - okaneco:add-codegen-tests, r=Mark-SimulacrumJacob Pratt-0/+182
Add codegen-llvm regression tests Most of these regressions deal with elimination of panics and bounds checks that were fixed upstream by LLVM. closes https://github.com/rust-lang/rust/issues/141497 closes https://github.com/rust-lang/rust/issues/131162 closes https://github.com/rust-lang/rust/issues/129583 closes https://github.com/rust-lang/rust/issues/110971 closes https://github.com/rust-lang/rust/issues/91109 closes https://github.com/rust-lang/rust/issues/80075 closes https://github.com/rust-lang/rust/issues/74917 closes https://github.com/rust-lang/rust/issues/71997 closes https://github.com/rust-lang/rust/issues/71257 closes https://github.com/rust-lang/rust/issues/59352
2025-08-21Rollup merge of #145661 - folkertdev:s390x-codegen-test-cleanup, r=dianqkJacob Pratt-17/+21
update some s390x codegen tests By using `minicore`, `&raw` and removing use of `link_llvm_intrinsics`
2025-08-21Rollup merge of #145137 - Kmeakin:km/optimize-slice-index-panicking, r=jhprattJacob Pratt-32/+24
Consolidate panicking functions in `slice/index.rs` Consolidate all the panicking functions in `slice/index.rs` to use a single `slice_index_fail` function, similar to how it is done in `str/traits.rs`. Split off from https://github.com/rust-lang/rust/pull/145024
2025-08-21Consolidate panicking functions in `slice/index.rs`Karl Meakin-32/+24
Consolidate all the panicking functions in `slice/index.rs` to use a single `slice_index_fail` function, similar to how it is done in `str/traits.rs`.
2025-08-21Fix LoongArch C function ABI when passing/returning structs containing floatsWANG Rui-8/+88
2025-08-21-Zsanitize and -Zsanitizer-cfi-normalize-integers flags are now target ↵Andrew Zhogin-35/+35
modifiers with custom consistency check function
2025-08-21Rollup merge of #145662 - GrigorenkoPV:x86-interrupt, r=compiler-errorsJacob Pratt-3/+3
Enforce correct number of arguments for `"x86-interrupt"` functions Tracking issue: rust-lang/rust#40180 Partially fixes rust-lang/rust#132835 `````@rustbot````` label: +F-abi_x86_interrupt +A-LLVM +O-x86_64 +O-x86_32 +A-ABI
2025-08-20Add codegen regression testsokaneco-0/+182
Most of these regressions concern elimination of panics and bounds checks that were fixed upstream by LLVM.
2025-08-20Auto merge of #145259 - nikic:read-only-capture, r=wesleywiserbors-11/+29
Tell LLVM about read-only captures `&Freeze` parameters are not only `readonly` within the function, but any captures of the pointer can also only be used for reads. This can now be encoded using the `captures(address, read_provenance)` attribute.
2025-08-20Auto merge of #144086 - clubby789:alloc-zeroed, r=nikicbors-0/+20
Pass `alloc-variant-zeroed` to LLVM Makes use of https://github.com/llvm/llvm-project/pull/138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires https://github.com/llvm/llvm-project/pull/149336 to work.~~ Closes rust-lang/rust#104847
2025-08-20Tell LLVM about read-only capturesNikita Popov-11/+29
`&Freeze` parameters are not only `readonly` within the function, but any captures of the pointer can also only be used for reads. This can now be encoded using the `captures(address, read_provenance)` attribute.
2025-08-20Pass `alloc-variant-zeroed` to LLVMclubby789-0/+20
2025-08-20Enforce correct number of arguments for `"x86-interrupt"` functionsPavel Grigorenko-3/+3
2025-08-20update some s390x codegen testsFolkert de Vries-17/+21
By using `minicore`, `&raw` and removing use of `link_llvm_intrinsics`
2025-08-20make `prefetch` intrinsics safeFolkert de Vries-40/+32
2025-08-19Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco许杰友 Jieyou Xu (Joe)-0/+18
Add `-Zindirect-branch-cs-prefix` Cc: ``@azhogin`` ``@Darksonn`` This goes on top of https://github.com/rust-lang/rust/pull/135927, i.e. please skip the first commit here. Please feel free to inherit it there. In fact, I am not sure if there is any use case for the flag without `-Zretpoline*`. GCC and Clang allow it, though. There is a `FIXME` for two `ignore`s in the test that I took from another test I did in the past -- they may be needed or not here since I didn't run the full CI. Either way, it is not critical. Tracking issue: https://github.com/rust-lang/rust/issues/116852. MCP: https://github.com/rust-lang/compiler-team/issues/868.
2025-08-19Rollup merge of #144567 - CaiWeiran:transmute-scalar_test, r=nikicStuart Cook-19/+12
Fix RISC-V Test Failures in ./x test for Multiple Codegen Cases This PR resolves several test failures encountered when running `./x test` on the RISC-V architecture. These failures were caused by platform-specific behavior, ABI differences, or codegen inconsistencies unique to RISC-V. The following test cases have been fixed to ensure compatibility with RISC-V: * `codegen-llvm/enum/enum-match.rs` * `codegen-llvm/enum/enum-transparent-extract.rs` * `codegen-llvm/repeat-operand-zero-len.rs` * `codegen-llvm/enum/enum-aggregate.rs` * `codegen-llvm/uninhabited-transparent-return-abi.rs` In addition, this PR adjusts `tests/codegen-llvm/transmute-scalar.rs` to explicitly specify the target architecture: ```rust //@ compile-flags: --target=x86_64-unknown-linux-gnu //@ needs-llvm-components: x86 ``` As suggested by ```@nikic,``` this test is not target-specific and already uses `minicore`, implying it is meant to run against a stable triple regardless of the host architecture. Explicitly setting the target ensures consistent codegen behavior, particularly when testing on non-x86 platforms such as riscv64. All changes have been tested locally on a RISC-V target and now pass as expected. ### Notes: * These fixes are scoped specifically to enable full test suite compliance for RISC-V. * No changes impact other architectures. * The change to `transmute-scalar.rs` aligns with the intent of [[#143915](https://github.com/rust-lang/rust/pull/143915)](https://github.com/rust-lang/rust/pull/143915) and prevents architecture-dependent discrepancies during CI or local testing.
2025-08-19Rollup merge of #142681 - 1c3t3a:sanitize-off-on, r=rcvalleStuart Cook-29/+199
Remove the `#[no_sanitize]` attribute in favor of `#[sanitize(xyz = "on|off")]` This came up during the sanitizer stabilization (rust-lang/rust#123617). Instead of a `#[no_sanitize(xyz)]` attribute, we would like to have a `#[sanitize(xyz = "on|off")]` attribute, which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off). The implementation is done according to what was [discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/343119-project-exploit-mitigations/topic/Stabilize.20the.20.60no_sanitize.60.20attribute/with/495377292)). The new attribute also works on modules, traits and impl items and thus enables usage as the following: ```rust #[sanitize(address = "off")] mod foo { fn unsanitized(..) {} #[sanitize(address = "on")] fn sanitized(..) {} } trait MyTrait { #[sanitize(address = "off")] fn unsanitized_default(..) {} } #[sanitize(thread = "off")] impl MyTrait for () { ... } ``` r? ```@rcvalle```
2025-08-18tests: fix RISC-V failures and adjust transmute-scalar.rs targetCaiweiran-19/+12
Resolve several ./x test failures on RISC-V caused by ABI and codegen differences. Update multiple codegen-llvm tests for compatibility, and explicitly set the target for transmute-scalar.rs to x86_64 to ensure consistent behavior across hosts.
2025-08-18Remove the no_sanitize attribute in favor of sanitizeBastian Kersting-29/+81
This removes the #[no_sanitize] attribute, which was behind an unstable feature named no_sanitize. Instead, we introduce the sanitize attribute which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off). This also makes sanitize(kernel_address = ..) attribute work with -Zsanitize=address To do it the same as how clang disables address sanitizer, we now disable ASAN on sanitize(kernel_address = "off") and KASAN on sanitize(address = "off"). The same was added to clang in https://reviews.llvm.org/D44981.
2025-08-18Implement the #[sanitize(..)] attributeBastian Kersting-0/+118
This change implements the #[sanitize(..)] attribute, which opts to replace the currently unstable #[no_sanitize]. Essentially the new attribute works similar as #[no_sanitize], just with more flexible options regarding where it is applied. E.g. it is possible to turn a certain sanitizer either on or off: `#[sanitize(address = "on|off")]` This attribute now also applies to more places, e.g. it is possible to turn off a sanitizer for an entire module or impl block: ```rust \#[sanitize(address = "off")] mod foo { fn unsanitized(..) {} #[sanitize(address = "on")] fn sanitized(..) {} } \#[sanitize(thread = "off")] impl MyTrait for () { ... } ``` This attribute is enabled behind the unstable `sanitize` feature.
2025-08-18Rollup merge of #145355 - clubby789:option-match-eq, r=nikicStuart Cook-0/+78
Add codegen test for issue 122734 Closes rust-lang/rust#122734
2025-08-17Add `-Zindirect-branch-cs-prefix` optionMiguel Ojeda-4/+4
This is intended to be used for Linux kernel RETPOLINE builds. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-08-17Add -Zindirect-branch-cs-prefix (from draft PR)Alice Ryhl-0/+18
2025-08-15stabilize strict provenance atomic ptrKivooeo-1/+0
2025-08-15stabilize array repeatKivooeo-2/+0
2025-08-15Rollup merge of #145120 - maurer:llvm-time, r=nikicStuart Cook-37/+37
llvm: Accept new LLVM lifetime format In llvm/llvm-project#150248 LLVM removed the size parameter from the lifetime format. Tolerate not having that size parameter.
2025-08-14Update autodiff tests for the new intrinsics implMarcelo Domínguez-92/+97
2025-08-13Add test for issue 122734Jamie Hill-Daniel-0/+78
2025-08-13Auto merge of #145093 - nikic:dead-on-return, r=nnethercotebors-5/+36
Set dead_on_return attribute for indirect arguments Set the dead_on_return attribute (added in LLVM 21) for arguments that are passed indirectly, but not byval. This indicates that the value of the argument on return does not matter, enabling additional dead store elimination. From LangRef: > This attribute indicates that the memory pointed to by the argument is dead upon function return, both upon normal return and if the calls unwinds, meaning that the caller will not depend on its contents. Stores that would be observable either on the return path or on the unwind path may be elided. > > Specifically, the behavior is as-if any memory written through the pointer during the execution of the function is overwritten with a poison value upon function return. The caller may access the memory, but any load not preceded by a store will return poison. > > This attribute does not imply aliasing properties. For pointer arguments that do not alias other memory locations, noalias attribute may be used in conjunction. Conversely, this attribute always implies dead_on_unwind. > > This attribute cannot be applied to return values. This fixes parts of https://github.com/rust-lang/rust/issues/96497.
2025-08-11llvm: Accept new LLVM lifetime formatMatthew Maurer-37/+37
LLVM removed the size parameter from the lifetime format. Tolerate not having that size parameter.
2025-08-11Set dead_on_return attribute for indirect argumentsNikita Popov-5/+36
Set the dead_on_return attribute (added in LLVM 21) for arguments that are passed indirectly, but not byval. This indicates that the value of the argument on return does not matter, enabling additional dead store elimination.
2025-08-10Rollup merge of #145064 - okaneco:saturating_sub_regression_tests, r=nikicJacob Pratt-0/+19
Add regression test for `saturating_sub` bounds check issue Add codegen test for issue where `valid_index.saturating_sub(X)` produced an extra bounds check. This was fixed by the LLVM upgrade. Closes rust-lang/rust#139759
2025-08-08Stop using uadd.with.overflowScott McMurray-3/+12
2025-08-08Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikicTrevor Gross-3/+3
atomicrmw on pointers: move integer-pointer cast hacks into backend Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere. This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely. Cc ```@nikic``` -- this is the best we can do right now, right? Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-08Rollup merge of #145051 - bjorn3:prevent_linkage_symbol_name_collision, ↵Stuart Cook-1/+1
r=petrochenkov Prevent name collisions with internal implementation details The implementation of the linkage attribute inside extern blocks defines symbols starting with _rust_extern_with_linkage_. If someone tries to also define this symbol you will get a symbol conflict or even an ICE. By adding an unpredictable component to the symbol name, this becomes less of an issue. Spawned from the discussion at [#t-compiler > About static variables &#96;_rust_extern_with_linkage_&#42;&#96;](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/About.20static.20variables.20.60_rust_extern_with_linkage_*.60) cc `@ywxt` Fixes https://github.com/rust-lang/rust/issues/144940
2025-08-07Add regression test for `saturating_sub` bounds check issueokaneco-0/+19
Add codegen test for issue where `valid_index.saturating_sub(X)` produced an extra bounds check. This was fixed by the LLVM upgrade.
2025-08-07Prevent name collisions with internal implementation detailsbjorn3-1/+1
The implementation of the linkage attribute inside extern blocks defines symbols starting with _rust_extern_with_linkage_. If someone tries to also define this symbol you will get a symbol conflict or even an ICE. By adding an unpredictable component to the symbol name, this becomes less of an issue.