about summary refs log tree commit diff
path: root/tests/codegen-llvm
AgeCommit message (Collapse)AuthorLines
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-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-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-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.
2025-08-06Revert "Preserve the .debug_gdb_scripts section"bjorn3-3/+1
This reverts commit 868bdde25b030e0b71a29a5dbc04a891036e702e.
2025-08-06[codegen] assume the tag, not the relative discriminantScott McMurray-42/+55
2025-08-05Preserve the .debug_gdb_scripts sectionSebastian Poeplau-1/+3
Make sure that compiler and linker don't optimize the section's contents away by adding the global holding the data to "llvm.used". The volatile load in the main shim is retained because "llvm.used", which translates to SHF_GNU_RETAIN on ELF targets, requires a reasonably recent linker; emitting the volatile load ensures compatibility with older linkers, at least when libstd is used. Pretty printers in dylib dependencies are now emitted by the main crate instead of the dylib; apart from matching how rlibs are handled, this approach has the advantage that `omit_gdb_pretty_printer_section` keeps working with dylib dependencies.
2025-08-04Rollup merge of #144559 - CaiWeiran:extract-insert-dyn_test, r=Mark-SimulacrumStuart Cook-9/+18
Enable extract-insert-dyn.rs test on RISC-V (riscv64) This PR adds support for running the `tests/codegen-llvm/simd/extract-insert-dyn.rs` test on the RISC-V (riscv64) architecture. Previously, this test would fail on RISC-V targets due to architecture-specific code generation issues. This patch modifies the test to ensure compatibility while preserving its intent. The change has been tested locally using `./x test` on a riscv64 target, and the test now passes as expected. ### Notes: - This change is scoped specifically to improve RISC-V compatibility. - It does not affect behavior or test results on other architectures.
2025-08-01Multiple bounds checking elision failureslucarlig-0/+19
2025-07-31Rollup merge of #144232 - xacrimon:explicit-tail-call, r=WaffleLapkinStuart Cook-0/+18
Implement support for `become` and explicit tail call codegen for the LLVM backend This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (https://github.com/rust-lang/rust/issues/112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged. During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
2025-07-30Rollup merge of #144042 - dpaoliello:verifyllvmcomp, r=jieyouxuStuart Cook-23/+21
Verify llvm-needs-components are not empty and match the --target value I recently discovered a test with an empty `llvm-needs-components` entry (fixed in rust-lang/rust#143979) which meant that it didn't work correctly when building Rust with a limited set of LLVM targets. This change makes a pair of improvements to prevent this issue from creeping in again: * When parsing directives with values, `compiletest` will now raise an error if there is an empty value. * Improved the `target_specific_tests` tidy checker to map targets to LLVM components, to verify that any existing `llvm-needs-components` contains the target being used. I also fixed all the issues flagged by the improved tidy checker.
2025-07-29Rollup merge of #144632 - nikic:llvm-21-tests, r=durin42Jacob Pratt-4/+10
Update some tests for LLVM 21 Fixes https://github.com/rust-lang/rust/issues/144604. Fixes https://github.com/rust-lang/rust/issues/144606. r? `@durin42`
2025-07-29Verify llvm-needs-components are not empty and match the --target valueDaniel Paoliello-23/+21
2025-07-29tests: Test line number in debuginfo for diverging function callsMartin Nordholts-0/+38
2025-07-29Rollup merge of #144407 - godzie44:godzie44/fix_dwarf_inconsistency, ↵Stuart Cook-0/+32
r=wesleywiser fix(debuginfo): disable overflow check for recursive non-enum types Commit b10edb4 introduce an overflow check when generating debuginfo for expanding recursive types. While this check works correctly for enums, it can incorrectly prune valid debug information for structures. For example see rust-lang/rust#143241 (https://github.com/rust-lang/rust/issues/143241#issuecomment-3073721477). Furthermore, for structures such check does not make sense, since structures with recursively expanding types simply will not compile (there is a `hir_analysis_recursive_generic_parameter` for that). closes rust-lang/rust#143241
2025-07-29Adjust enum-discriminant-eq.rs for LLVM 21Nikita Popov-4/+10
The two xors get folded into the select.
2025-07-28Fix tests/codegen-llvm/simd/extract-insert-dyn.rs test failure on riscv64Caiweiran-9/+18
2025-07-27Auto merge of #144225 - purplesyringa:unwinding-intrinsics, r=nikicbors-1/+15
Don't special-case llvm.* as nounwind Certain LLVM intrinsics, such as `llvm.wasm.throw`, can unwind. Marking them as nounwind causes us to skip cleanup of locals and optimize out `catch_unwind` under inlining or when `llvm.wasm.throw` is used directly by user code. The motivation for forcibly marking llvm.* as nounwind is no longer present: most intrinsics are linked as `extern "C"` or other non-unwinding ABIs, so we won't codegen `invoke` for them anyway. Closes rust-lang/rust#132416. `@rustbot` label +T-compiler +A-panic
2025-07-27fix(debuginfo): disable overflow check forgodzie44-0/+32
recursive non-enum types
2025-07-27Auto merge of #144347 - scottmcm:ssa-enums-v0, r=WaffleLapkinbors-0/+31
No longer need `alloca`s for consuming `Result<!, i32>` and similar In optimized builds GVN gets rid of these already, but in `opt-level=0` we actually make `alloca`s for this, which particularly impacts `?`-style things that use actually-only-one-variant types like this. While doing so, rewrite `LocalAnalyzer::process_place` to be non-recursive, solving a 6+ year old FIXME. r? codegen
2025-07-26Rollup merge of #144359 - RalfJung:vararg-codegen, r=compiler-errorsJacob Pratt-0/+86
add codegen test for variadics This is a part of https://github.com/rust-lang/rust/pull/144066 that can land without FCP.
2025-07-26Auto merge of #143860 - scottmcm:transmute-always-rvalue, r=WaffleLapkinbors-10/+192
Let `codegen_transmute_operand` just handle everything When combined with rust-lang/rust#143720, this means `rvalue_creates_operand` can just return `true` for *every* `Rvalue`. (A future PR could consider removing it, though just letting it optimize out is fine for now.) It's nicer anyway, IMHO, because it avoids needing the layout checks to be consistent in the two places, and thus is an overall reduction in code. Plus it's a more helpful building block when used in other places this way. (TBH, it probably would have been better to have it this way the whole time, but I clearly didn't understand `rvalue_creates_operand` when I originally wrote rust-lang/rust#109843.)
2025-07-26Rollup merge of #144341 - CaiWeiran:const-vector_test, r=wesleywiserTrevor Gross-0/+2
Enable const-vector.rs test on RISC-V (riscv64) This PR replaces [#144283](https://github.com/rust-lang/rust/pull/144283) to resolve merge conflicts. This PR adds support for running the `tests/codegen/const-vector.rs` test on the RISC-V (riscv64) architecture. Previously, this test would fail on RISC-V targets due to architecture-specific code generation issues. This patch modifies the test to ensure compatibility while preserving its intent. The change has been tested locally using `./x test` on a riscv64 target, and the test now passes as expected. ### Notes: - This change is scoped specifically to improve RISC-V compatibility. - It does not affect behavior or test results on other architectures.
2025-07-26Implement support for explicit tail calls in the MIR block builders and the ↵Joel Wejdenstål-0/+18
LLVM codegen backend.
2025-07-23Don't emit two `assume`s in transmutes when one is a subset of the otherScott McMurray-8/+41
For example, transmuting between `bool` and `Ordering` doesn't need two `assume`s because one range is a superset of the other. Multiple are still used for things like `char` <-> `NonZero<u32>`, which overlap but where neither fully contains the other.
2025-07-23re-enable direct `bitcast`s for Int/Float vector transmutes (but not ones ↵Scott McMurray-0/+176
involving pointers)
2025-07-23Let `codegen_transmute_operand` just handle everythingScott McMurray-10/+16
When combined with 143720, this means `rvalue_creates_operand` can just return `true` for *every* `Rvalue`. (A future PR could consider removing it, though just letting it optimize out is fine for now.) It's nicer anyway, IMHO, because it avoids needing the layout checks to be consistent in the two places, and thus is an overall reduction in code. Plus it's a more helpful building block when used in other places this way.