about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2025-09-05Rollup merge of #146144 - heiher:entry-func-features, r=petrochenkovLeón Orell Valerian Liehr-10/+22
compiler: Apply target features to the entry function Fixes rust-lang/rust#146143
2025-09-05gpu offload: change suspicious map into filterMarijn Schouten-1/+1
2025-09-04compiler: Apply target features to the entry functionWANG Rui-10/+22
2025-09-04Auto merge of #145955 - bjorn3:lto_refactors4, r=nnethercotebors-15/+7
Rework how the codegen coordinator code handles the allocator shim Continuing from https://github.com/rust-lang/rust/pull/144503 this centralizes most handling of the allocator shim to a single 4 line block in the codegen coordinator. The allocator shim is small enough that making it go through the main codegen loop and spawning a worker thread for it is wasted effort.
2025-09-04Special case allocator module submission to avoid special casing it elsewherebjorn3-15/+7
A lot of places had special handling just in case they would get an allocator module even though most of these places could never get one or would have a trivial implementation for the allocator module. Moving all handling of the allocator module to a single place simplifies things a fair bit.
2025-09-04Rollup merge of #145690 - sayantn:integer-funnel-shift, r=tgross35Jacob Pratt-8/+18
Implement Integer funnel shifts Tracking issue: rust-lang/rust#145686 ACP: https://github.com/rust-lang/libs-team/issues/642 This implements funnel shifts on primitive integer types. Implements this for cg_llvm, with a fallback impl for everything else Thanks `@folkertdev` for the fixes and tests cc `@rust-lang/libs-api`
2025-09-04Rollup merge of #146134 - maurer:nvptx-sync, r=durin42Stuart Cook-0/+4
llvm: nvptx: Layout update to match LLVM LLVM upstream switched layouts to support 256-bit vector load/store. ``````@rustbot`````` label llvm-main r? durin42
2025-09-04Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=jackh726Stuart Cook-13/+47
Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`. Rather than adding the inline always attribute to the function definition, we add it to the callsite. We can then check that the target features match and that the call would be safe to inline. If the function isn't inlined due to a mismatch, we emit a warning informing the user that the function can't be inlined due to the target feature mismatch. See tracking issue rust-lang/rust#145574
2025-09-03Add `funnel_sh{l,r}` functions and intrinsicssayantn-8/+18
- Add a fallback implementation for the intrinsics - Add LLVM backend support for funnel shifts Co-Authored-By: folkertdev <folkert@folkertdev.nl>
2025-09-02llvm: nvptx: Layout update to match LLVMMatthew Maurer-0/+4
LLVM upstream switched layouts to support 256-bit vector load/store.
2025-09-02Auto merge of #146059 - folkertdev:va-end-lifetime, r=saethlinbors-3/+6
explicitly end the lifetime of `va_list` tracking issue: https://github.com/rust-lang/rust/issues/44930 split out from: https://github.com/rust-lang/rust/pull/144549 The `va_list` is created in the compiler itself when the variable argument list `...` is desugared, and hence the lifetime end is not inserted automatically. The value can't outlive the function in which it was created, so it is correct to end the lifetime here. Ending the lifetime explicitly also appears to give slightly better codegen in https://github.com/rust-lang/rust/pull/144549. I also included a little drive-by improvement to not cast pointers to integers and back again. r? codegen
2025-09-01Auto merge of #145721 - dpaoliello:ar050, r=bjorn3bors-0/+7
Update to ar_archive_writer 0.5 This updates `ar_archive_writer` to 0.5, which in turn was updated to match LLVM 20.1.8: <https://github.com/rust-lang/ar_archive_writer/pull/24> As part of this, I refactored part of `SymbolWrapper.cpp` to pull common code that I was about to duplicate again into a new function. NOTE: `ar_archive_writer` does include a breaking change where it no longer supports mangling C++ mangled names for Arm64EC. Since we don't need the mangled name (it's not the "exported name" which we're trying to load from the external dll), I'm setting the `import_name` when building for Arm64EC to prevent error when failing to mangle. r? `@bjorn3`
2025-08-31round pointer to alignment without going via intFolkert de Vries-3/+6
2025-08-30compiler: Include span of too huge array with `-Cdebuginfo=2`Martin Nordholts-4/+10
We have a few ui tests to ensure we emit an error if we encounter too big arrays. Before this fix, compiling the tests with `-Cdebuginfo=2` would not include the spans of the instantiation sites, because the error is then emitted from a different code path that does not include the span. Propagate the span to the error also in the debuginfo case, so the tests passes regardless of debuginfo level.
2025-08-29Rollup merge of #145967 - Enselic:big-enum-debuginfo-span, r=wesleywiserTrevor Gross-6/+19
compiler: Include span of too huge enum with `-Cdebuginfo=2` We have the ui test `tests/ui/limits/huge-enum.rs` to ensure we emit an error if we encounter too big enums. Before this fix, compiling the test with `-Cdebuginfo=2` would not include the span of the instantiation site, because the error is then emitted from a different code path that does not include the span. Propagate the span to the error also in the debuginfo case, so the test passes regardless of debuginfo level. I'm sure we can propagate spans in more places, but let's start small. ## Test failure without the fix Here is what the failure looks like if you run the test without the fix: ``` [ui] tests/ui/limits/huge-enum.rs#full-debuginfo ... F . failures: ---- [ui] tests/ui/limits/huge-enum.rs#full-debuginfo stdout ---- Saved the actual stderr to `/home/martin/src/rust/build/x86_64-unknown-linux-gnu/test/ui/limits/huge-enum.full-debuginfo/huge-enum.full-debuginfo.stderr` diff of stderr: 1 error: values of the type `Option<TYPE>` are too big for the target architecture - --> $DIR/huge-enum.rs:17:9 - | - LL | let big: BIG = None; - | ^^^ 6 7 error: aborting due to 1 previous error 8 The actual stderr differed from the expected stderr To update references, rerun the tests and pass the `--bless` flag To only update this specific test, also pass `--test-args limits/huge-enum.rs` ``` as can be seen, the `span` used to be missing with `debuginfo=2`. ## See also This is one small step towards resolving rust-lang/rust#61117. cc https://github.com/rust-lang/rust/pull/144499 which began running UI tests with `rust.debuginfo-level-tests=1`. This PR is part of preparing for increasing that to debuglevel 2.
2025-08-29Update to ar_archive_writer 0.5.1Daniel Paoliello-0/+7
2025-08-28Move ___asan_globals_registered exportbjorn3-0/+4
All other sanitizer symbols are handled in prepare_lto already.
2025-08-28Only export the sanitizer symbols for LTO and move export code to cg_llvmbjorn3-0/+28
Don't export them from cdylibs. There is no need to do so and it complicates exported_non_generic_symbols. In addition the GCC backend likely uses different symbols and may potentially not even need us to explicitly tell it to export the symbols it needs.
2025-08-28compiler: Include span of too huge enum with -Cdebuginfo=2Martin Nordholts-6/+19
We have a ui test to ensure we emit an error if we encounter too big enums. Before this fix, compiling the test with `-Cdebuginfo=2` would not include the span of the instantiation site, because the error is then emitted from a different code path that does not include the span. Propagate the span to the error also in the debuginfo case, so the test passes regardless of debuginfo level.
2025-08-28Auto merge of #145877 - nikic:capture-address, r=tmiaskobors-4/+6
Use captures(address) instead of captures(none) for indirect args While provenance cannot be captured through these arguments, the address / object identity can. Fixes https://github.com/rust-lang/rust/issues/137668. r? `@ghost`
2025-08-27inline at the callsite & warn when target features mismatchJames Barford-Evans-13/+47
Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
2025-08-26Rollup merge of #145867 - Zalathar:range-attr, r=nikicGuillaume Gomez-11/+27
cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes that each of `LowerWords` and `UpperWords` points to enough u64 values to define an integer of the specified bit-length, and will encounter UB if that is not the case. Our safe wrapper function always passes pointers to `[u64; 2]` arrays, regardless of the bit-length specified. That's fine in practice, because scalar primitives never exceed 128 bits, but it is technically a soundness hole in a safe function. We can close the soundness hole by explicitly asserting `size_bits <= 128`. This is effectively just a stricter version of the existing check that the value must be small enough to fit in `c_uint`. --- This is a narrower version of the fix in rust-lang/rust#145846.
2025-08-26Rollup merge of #145076 - ZhongyaoChen:feature/add-tier3-riscv64a23-target, ↵Guillaume Gomez-1/+1
r=davidtwco Add new Tier-3 target: riscv64a23-unknown-linux-gnu MCP: [Tier 3 target proposal: riscv64a23-unknown-linux-gnu](https://github.com/rust-lang/compiler-team/issues/894) Changes: - add new target: riscv64a23-unknown-linux-gnu - add target page
2025-08-26Use captures(address) instead of captures(none) for indirect argsNikita Popov-4/+6
While provenance cannot be captured through these arguments, the address / object identity can.
2025-08-26Rollup merge of #145814 - bjorn3:codegen_worker_fatal_error, r=petrochenkovStuart Cook-67/+66
Handle unwinding fatal errors in codegen workers Also directly unwind on fatal errors at the point they are emitted inside the codegen backends. Fixes the coordinator ICE of https://github.com/rust-lang/rust/issues/132240, https://github.com/rust-lang/rust/issues/135075 and https://github.com/rust-lang/rust/issues/145800.
2025-08-26Assert that LLVM range-attribute values don't exceed 128 bitsZalathar-11/+27
The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes that each of `LowerWords` and `UpperWords` points to enough u64 values to define an integer of the specified bit-length, and will encounter UB if that is not the case. Our safe wrapper function always passes pointers to `[u64; 2]` arrays, regardless of the bit-length specified. That's fine in practice, because scalar primitives never exceed 128 bits, but it is technically a soundness hole in a safe function. We can close the soundness hole by explicitly asserting `size_bits <= 128`. This is effectively just a stricter version of the existing check that the value must be small enough to fit in `c_uint`.
2025-08-24Rename `llvm::Bool` aliases to standard const caseZalathar-34/+33
This avoids the need for `#![allow(non_upper_case_globals)]`.
2025-08-24Replace the `llvm::Bool` typedef with a proper newtypeZalathar-34/+75
2025-08-24Directly raise fatal errors inside the codegen backendsbjorn3-67/+66
As opposed to passing it around through Result.
2025-08-21Rollup merge of #145705 - folkertdev:prefetch-remove-as-cast, r=RalfJungJacob Pratt-1/+1
remove an `as` cast in prefetch codegen r? `@RalfJung`
2025-08-21remove an `as` cast in prefetch codegenFolkert de Vries-1/+1
2025-08-21Rollup merge of #145297 - adwinwhite:recursive-debuginfo, r=wesleywiserJacob Pratt-16/+38
fix(debuginfo): handle false positives in overflow check Fixes rust-lang/rust#144636. Duplicate wrappers and normal recursive types can lead to false positives. ```rust struct Recursive { a: Box<Box<Recursive>>, } ``` The ADT stack can be: - `Box<Recursive>` - `Recursive` - `Box<Box<Recursive>>` (`Box` now detected as expanding) We can filter them out by tracing the generic arg back through the stack, as true expanding recursive types must have their expanding arg used as generic arg throughout. r? ````@wesleywiser````
2025-08-20Auto merge of #145259 - nikic:read-only-capture, r=wesleywiserbors-1/+7
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/+10
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-1/+7
`&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/+10
2025-08-20Rollup merge of #145626 - folkertdev:prefetch-fallback, r=AmanieuJacob Pratt-1/+7
add a fallback implementation for the `prefetch_*` intrinsics related ACP: https://github.com/rust-lang/libs-team/issues/638 The fallback is to just ignore the arguments. That is a valid implementation because this intrinsic is just a hint. I also added the `miri::intrinsic_fallback_is_spec` annotation, so that miri now supports these operations. A prefetch intrinsic call is valid on any pointer. (specifically LLVM guarantees this https://llvm.org/docs/LangRef.html#llvm-prefetch-intrinsic) Next, I made the `LOCALITY` argument a const generic. That argument must be const (otherwise LLVM crashes), but that was not reflected in the type. Finally, with these changes, the intrinsic can be safe and `const` (a prefetch at const evaluation time is just a no-op). cc `@Amanieu` r? `@RalfJung`
2025-08-20make `prefetch` intrinsics safeFolkert de Vries-1/+7
2025-08-19Auto merge of #145600 - jieyouxu:rollup-jw0bpnt, r=jieyouxubors-1/+1
Rollup of 15 pull requests Successful merges: - rust-lang/rust#145338 (actually provide the correct args to coroutine witnesses) - rust-lang/rust#145429 (Couple of codegen_fn_attrs improvements) - rust-lang/rust#145452 (Do not strip binaries in bootstrap everytime if they are unchanged) - rust-lang/rust#145464 (Stabilize `const_pathbuf_osstring_new` feature) - rust-lang/rust#145474 (Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups) - rust-lang/rust#145486 (Fix `unicode_data.rs` mention message) - rust-lang/rust#145490 (Trace some basic I/O operations in bootstrap) - rust-lang/rust#145493 (remove `should_render` in `PrintAttribute` derive) - rust-lang/rust#145500 (Port must_use to the new target checking) - rust-lang/rust#145505 (Simplify span caches) - rust-lang/rust#145510 (Visit and print async_fut local for async drop.) - rust-lang/rust#145511 (Rust build fails on OpenBSD after using file_lock feature) - rust-lang/rust#145532 (resolve: debug for block module) - rust-lang/rust#145533 (Reorder `lto` options from most to least optimizing) - rust-lang/rust#145537 (Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-19Rollup merge of #145429 - bjorn3:codegen_fn_attrs_improvements, r=jdonszelmann许杰友 Jieyou Xu (Joe)-1/+1
Couple of codegen_fn_attrs improvements As noted in https://github.com/rust-lang/rust/pull/144678#discussion_r2245060329 here is no need to keep link_name and export_name separate, which the third commit fixes by merging them. The second commit removes some dead code and the first commit merges two ifs with equivalent conditions. The last commit is an unrelated change which removes an unused `feature(autodiff)`.
2025-08-19Rollup merge of #145099 - heiher:loong-32s, r=folkertdev许杰友 Jieyou Xu (Joe)-0/+1
rustc_target: Add the `32s` target feature for LoongArch LLVM: https://github.com/llvm/llvm-project/pull/139695
2025-08-19Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco许杰友 Jieyou Xu (Joe)-0/+9
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 #145484 - Zalathar:archive-builder, r=bjorn3Stuart Cook-334/+6
Remove `LlvmArchiveBuilder` and supporting code/bindings Switching over to the newer Rust-based `ArArchiveBuilder` happened in rust-lang/rust#128936, a year ago. Per the comment in `new_archive_builder`, that seems like enough time to justify removing the older, unused `LlvmArchiveBuilder` implementation and its associated bindings. Fixes rust-lang/rust#128955.
2025-08-19Rollup merge of #145432 - Zalathar:target-machine, r=wesleywiserStuart Cook-17/+14
cg_llvm: Small cleanups to `owned_target_machine` This PR contains a few tiny cleanups to the `owned_target_machine` code. Each individual commit should be fairly straightforward.
2025-08-19completely remove rva23s64Zhongyao Chen-5/+1
2025-08-18Rollup merge of #145420 - Zalathar:llvm-c, r=WaffleLapkinStuart Cook-9/+14
cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind` This PR replaces two existing `LLVMRust` bindings with equivalent calls to the LLVM-C API. For `LLVMGetTypeKind`, we avoid the UB hazard by declaring the foreign function to return `RawEnum<TypeKind>` (which is a wrapper around `u32`), and then perform checked conversion from `u32` to `TypeKind`.
2025-08-18Rollup merge of #145309 - winstonallo:issue-145271-fix, r=tgross35Stuart Cook-0/+9
Fix `-Zregparm` for LLVM builtins This fixes the issue where `-Zregparm=N` was not working correctly when calling LLVM intrinsics By default on `x86-32`, arguments are passed on the stack. The `-Zregparm=N` flag allows the first `N` arguments to be passed in registers instead. When calling intrinsics like `memset`, LLVM still passes parameters on the stack, which prevents optimizations like tail calls. As proposed by ````@tgross35,```` I fixed this by setting the `NumRegisterParameters` LLVM module flag to `N` when the `-Zregparm=N` is set. ```rust // compiler/rust_codegen_llvm/src/context.rs#375-382 if let Some(regparm_count) = sess.opts.unstable_opts.regparm { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Error, "NumRegisterParameters", regparm_count, ); } ``` [Here](https://rust.godbolt.org/z/YMezreo48) is a before/after compiler explorer. Here is the final result for the code snippet in the original issue: ```asm entrypoint: push esi mov esi, eax mov eax, ecx mov ecx, esi pop esi jmp memset ; Tail call parameters in registers ``` Fixes: https://github.com/rust-lang/rust/issues/145271
2025-08-17Add -Zindirect-branch-cs-prefix (from draft PR)Alice Ryhl-0/+9
2025-08-16Remove `LlvmArchiveBuilder` and supporting code/bindingsZalathar-334/+6
2025-08-15Simplify the `args_cstr_buff` assertionZalathar-5/+4