about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
AgeCommit message (Collapse)AuthorLines
2025-02-09Auto merge of #136754 - Urgau:rollup-qlkhjqr, r=Urgaubors-1/+5
Rollup of 5 pull requests Successful merges: - #134679 (Windows: remove readonly files) - #136213 (Allow Rust to use a number of libc filesystem calls) - #136530 (Implement `x perf` directly in bootstrap) - #136601 (Detect (non-raw) borrows of null ZST pointers in CheckNull) - #136659 (Pick the max DWARF version when LTO'ing modules with different versions ) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-08Rollup merge of #136706 - workingjubilee:finish-up-rustc-abi-updates, ↵Jubilee-6/+5
r=compiler-errors compiler: mostly-finish `rustc_abi` updates This almost-finishes all the updates in the compiler to use `rustc_abi` and removes some of the reexports of `rustc_abi` items in `rustc_target` that were previously available. r? ```@compiler-errors```
2025-02-09Rollup merge of #136659 - wesleywiser:dwarf_version_lto_merge_behavior, ↵Urgau-1/+5
r=jieyouxu Pick the max DWARF version when LTO'ing modules with different versions Currently, when rustc compiles code with `-Clto` enabled that was built with different choices for `-Zdwarf-version`, a warning will be reported. It's very easy to observe this by compiling most anything (eg, "hello world") and specifying `-Clto -Zdwarf-version=5` since the standard library is distributed with `-Zdwarf-version=4`. This behavior isn't actually useful for a few reasons: - From observation, LLVM chooses to pick the highest DWARF version anyway after issuing the warning. - Clang specifies that in this case, the max version should be picked without a warning and as a general principle, we want to support x-lang LTO with Clang which implies using the same module flag merge behaviors. - Debuggers need to be able to handle a variety of versions within the same debugging session as you can easily have some parts of a binary (or some dynamic libraries within an application) all compiled with different DWARF versions. This commit changes the module flag merge behavior to match Clang and use the highest version of DWARF. It also adds a test to ensure this behavior is respected in the case of two crates being LTO'd together and adds a test to ensure no warning is printed. Fixes #130041 which fails due to these warnings being printed cc #103057
2025-02-08Rustfmtbjorn3-264/+290
2025-02-08Pick the max DWARF version when LTO'ing modules with different versionsWesley Wiser-1/+5
Currently, when rustc compiles code with `-Clto` enabled that was built with different choices for `-Zdwarf-version`, a warning will be reported. It's very easy to observe this by compiling most anything (eg, "hello world") and specifying `-Clto -Zdwarf-version=5` since the standard library is distributed with `-Zdwarf-version=4`. This behavior isn't actually useful for a few reasons: - from observation, LLVM chooses to pick the highest DWARF version anyway after issuing the warning - Clang specifies that in this case, the max version should be picked without a warning and as a general principle, we want to support x-lang LTO with Clang which implies using the same module flag merge behaviors - Debuggers need to be able to handle a variety of versions withing the same debugging session as you can easily have some parts of a binary (or some dynamic libraries within an application) all compiled with different DWARF versions This commit changes the module flag merge behavior to match Clang and use the highest version of DWARF. It also adds a test to ensure this behavior is respected in the case of two crates being LTO'd together and updates the test added in the previous commit to ensure no warning is printed.
2025-02-07fix non-enzyme buildsManuel Drehwald-1/+4
2025-02-08Rollup merge of #136691 - bjorn3:linkage_cleanup, r=jieyouxuMatthias Krüger-6/+1
Remove Linkage::Private and Linkage::Appending Neither of them has any use case. Neither known nor theoretical.
2025-02-08Rollup merge of #136640 - Zalathar:debuginfo-align-bits, r=compiler-errorsMatthias Krüger-8/+5
Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit In #116096, function ZSTs were made to have debuginfo that gives them an alignment of “1”. But because alignment in LLVM debuginfo is denoted in *bits*, not bytes, this resulted in an alignment specification of 1 bit instead of 1 byte. I don't know whether this has any practical consequences, but I noticed that a test started failing when I accidentally fixed the mistake while working on #136632, so I extracted the fix (and the test adjustment) to this PR.
2025-02-07compiler: remove reexports from rustc_target::callconvJubilee Young-6/+5
2025-02-07rustc_target: Add the fp16 target feature for AArch32Kajetan Puchalski-0/+1
2025-02-07Remove Linkage::Appendingbjorn3-1/+0
It can only be used for certain LLVM internal variables like llvm.global_ctors which users are not allowed to define.
2025-02-07Remove Linkage::Privatebjorn3-5/+1
This is the same as Linkage::Internal except that it doesn't emit any symbol. Some backends may not support it and it isn't all that useful anyway.
2025-02-06Remove dead code from rustc_codegen_llvm and the LLVM wrapperDaniel Paoliello-29/+0
2025-02-06Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bitZalathar-8/+5
2025-02-06Auto merge of #136471 - safinaskar:parallel, r=SparrowLiibors-2/+2
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` This is continuation of https://github.com/rust-lang/rust/pull/132282 . I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement. There are other possibilities, through. We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase. So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge. cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 ) r? SparrowLii `@rustbot` label WG-compiler-parallel
2025-02-06coverage: Remove the old code for simplifying counters after MIR optsZalathar-19/+10
2025-02-06coverage: Defer part of counter-creation until codegenZalathar-23/+10
2025-02-06coverage: Store BCB node IDs in mappings, and resolve them in codegenZalathar-12/+17
Even though the coverage graph itself is no longer available during codegen, its nodes can still be used as opaque IDs.
2025-02-06Remove some unused glob re-exportsZalathar-4/+0
These were detected by temporarily making `mod llvm` non-public.
2025-02-06Remove the `mod llvm_` hack, which should no longer be necessaryZalathar-8/+3
2025-02-05fix fwd-mode autodiff caseManuel Drehwald-3/+8
2025-02-05Rollup merge of #136375 - Zalathar:llvm-di-builder, r=workingjubileeLeón Orell Valerian Liehr-62/+121
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1) Part of #134001, follow-up to #136326, extracted from #134009. This PR performs an arbitrary subset of the LLVM-C binding migrations from #134009, which should make it less tedious to review. The remaining migrations can occur in one or more subsequent PRs.
2025-02-04Auto merge of #135760 - scottmcm:disjoint-bitor, r=WaffleLapkinbors-0/+17
Add `unchecked_disjoint_bitor` per ACP373 Following the names from libs-api in https://github.com/rust-lang/libs-team/issues/373#issuecomment-2085686057 Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
2025-02-04nvptx64: update default alignment to match LLVM 21Augie Fackler-0/+6
This changed in llvm/llvm-project@91cb8f5d3202870602c6bef807bc4c7ae8a32790. The commit itself is mostly about some intrinsic instructions, but as an aside it also mentions something about addrspace for tensor memory, which I believe is what this string is telling us. @rustbot label: +llvm-main
2025-02-04intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even ↵Ralf Jung-14/+8
intrinsic
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-2/+2
2025-02-02Handle the case where the `or disjoint` folds immediately to a constantScott McMurray-1/+7
2025-02-02Rollup merge of #136426 - oli-obk:push-nkpuulwurykn, r=compiler-errorsMatthias Krüger-2/+8
Explain why we retroactively change a static initializer to have a different type I keep getting confused about it and in turn confused `@GuillaumeGomez` while trying to explain it badly
2025-02-01Explain why we retroactively change a static initializer to have a different ↵Oli Scherer-2/+8
type
2025-01-31Override `disjoint_or` in the LLVM backendScott McMurray-0/+11
2025-02-01Explain why (some) pointer/length strings are `*const c_uchar`Zalathar-0/+12
2025-02-01Add FIXME for auditing optional parameters passed to DIBuilderZalathar-0/+4
2025-02-01Use `LLVMDIBuilderCreateDebugLocation`Zalathar-7/+9
The LLVM-C binding takes an explicit context, whereas our binding obtained the context from the scope argument.
2025-02-01Use `LLVMDIBuilderCreateLexicalBlockFile`Zalathar-10/+17
2025-02-01Use `LLVMDIBuilderCreateLexicalBlock`Zalathar-9/+9
2025-02-01Use `LLVMDIBuilderCreateNameSpace`Zalathar-17/+18
2025-02-01Use `LLVMDIBuilderFinalize`Zalathar-3/+3
2025-02-01Introduce `DIBuilderBox`, an owning pointer to `DIBuilder`Zalathar-20/+53
2025-01-31Add link attribute for Enzyme's FFIBen Kimock-2/+7
2025-01-31Auto merge of #136332 - jhpratt:rollup-aa69d0e, r=jhprattbors-9/+11
Rollup of 9 pull requests Successful merges: - #132156 (When encountering unexpected closure return type, point at return type/expression) - #133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle) - #136281 (`rustc_hir_analysis` cleanups) - #136297 (Fix a typo in profile-guided-optimization.md) - #136300 (atomic: extend compare_and_swap migration docs) - #136310 (normalize `*.long-type.txt` paths for compare-mode tests) - #136312 (Disable `overflow_delimited_expr` in edition 2024) - #136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics) - #136323 (Fix a typo in conventions.md) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-31Rollup merge of #133429 - EnzymeAD:autodiff-middle, r=oli-obkJacob Pratt-9/+11
Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle This PR should not be merged until the rustc_codegen_llvm part is merged. I will also alter it a little based on what get's shaved off from the cg_llvm PR, and address some of the feedback I received in the other PR (including cleanups). I am putting it already up to 1) Discuss with `@jieyouxu` if there is more work needed to add tests to this and 2) Pray that there is someone reviewing who can tell me why some of my autodiff invocations get lost. Re 1: My test require fat-lto. I also modify the compilation pipeline. So if there are any other llvm-ir tests in the same compilation unit then I will likely break them. Luckily there are two groups who currently have the same fat-lto requirement for their GPU code which I have for my autodiff code and both groups have some plans to enable support for thin-lto. Once either that work pans out, I'll copy it over for this feature. I will also work on not changing the optimization pipeline for functions not differentiated, but that will require some thoughts and engineering, so I think it would be good to be able to run the autodiff tests isolated from the rest for now. Can you guide me here please? For context, here are some of my tests in the samples folder: https://github.com/EnzymeAD/rustbook Re 2: This is a pretty serious issue, since it effectively prevents publishing libraries making use of autodiff: https://github.com/EnzymeAD/rust/issues/173. For some reason my dummy code persists till the end, so the code which calls autodiff, deletes the dummy, and inserts the code to compute the derivative never gets executed. To me it looks like the rustc_autodiff attribute just get's dropped, but I don't know WHY? Any help would be super appreciated, as rustc queries look a bit voodoo to me. Tracking: - https://github.com/rust-lang/rust/issues/124509 r? `@jieyouxu`
2025-01-31Auto merge of #135318 - compiler-errors:vtable-fixes, r=lcnrbors-15/+18
Fix deduplication mismatches in vtables leading to upcasting unsoundness We currently have two cases where subtleties in supertraits can trigger disagreements in the vtable layout, e.g. leading to a different vtable layout being accessed at a callsite compared to what was prepared during unsizing. Namely: ### #135315 In this example, we were not normalizing supertraits when preparing vtables. In the example, ``` trait Supertrait<T> { fn _print_numbers(&self, mem: &[usize; 100]) { println!("{mem:?}"); } } impl<T> Supertrait<T> for () {} trait Identity { type Selff; } impl<Selff> Identity for Selff { type Selff = Selff; } trait Middle<T>: Supertrait<()> + Supertrait<T> { fn say_hello(&self, _: &usize) { println!("Hello!"); } } impl<T> Middle<T> for () {} trait Trait: Middle<<() as Identity>::Selff> {} impl Trait for () {} fn main() { (&() as &dyn Trait as &dyn Middle<()>).say_hello(&0); } ``` When we prepare `dyn Trait`, we see a supertrait of `Middle<<() as Identity>::Selff>`, which itself has two supertraits `Supertrait<()>` and `Supertrait<<() as Identity>::Selff>`. These two supertraits are identical, but they are not duplicated because we were using structural equality and *not* considering normalization. This leads to a vtable layout with two trait pointers. When we upcast to `dyn Middle<()>`, those two supertraits are now the same, leading to a vtable layout with only one trait pointer. This leads to an offset error, and we call the wrong method. ### #135316 This one is a bit more interesting, and is the bulk of the changes in this PR. It's a bit similar, except it uses binder equality instead of normalization to make the compiler get confused about two vtable layouts. In the example, ``` trait Supertrait<T> { fn _print_numbers(&self, mem: &[usize; 100]) { println!("{mem:?}"); } } impl<T> Supertrait<T> for () {} trait Trait<T, U>: Supertrait<T> + Supertrait<U> { fn say_hello(&self, _: &usize) { println!("Hello!"); } } impl<T, U> Trait<T, U> for () {} fn main() { (&() as &'static dyn for<'a> Trait<&'static (), &'a ()> as &'static dyn Trait<&'static (), &'static ()>) .say_hello(&0); } ``` When we prepare the vtable for `dyn for<'a> Trait<&'static (), &'a ()>`, we currently consider the PolyTraitRef of the vtable as the key for a supertrait. This leads two two supertraits -- `Supertrait<&'static ()>` and `for<'a> Supertrait<&'a ()>`. However, we can upcast[^up] without offsetting the vtable from `dyn for<'a> Trait<&'static (), &'a ()>` to `dyn Trait<&'static (), &'static ()>`. This is just instantiating the principal trait ref for a specific `'a = 'static`. However, when considering those supertraits, we now have only one distinct supertrait -- `Supertrait<&'static ()>` (which is deduplicated since there are two supertraits with the same substitutions). This leads to similar offsetting issues, leading to the wrong method being called. [^up]: I say upcast but this is a cast that is allowed on stable, since it's not changing the vtable at all, just instantiating the binder of the principal trait ref for some lifetime. The solution here is to recognize that a vtable isn't really meaningfully higher ranked, and to just treat a vtable as corresponding to a `TraitRef` so we can do this deduplication more faithfully. That is to say, the vtable for `dyn for<'a> Tr<'a>` and `dyn Tr<'x>` are always identical, since they both would correspond to a set of free regions on an impl... Do note that `Tr<for<'a> fn(&'a ())>` and `Tr<fn(&'static ())>` are still distinct. ---- There's a bit more that can be cleaned up. In codegen, we can stop using `PolyExistentialTraitRef` basically everywhere. We can also fix SMIR to stop storing `PolyExistentialTraitRef` in its vtable allocations. As for testing, it's difficult to actually turn this into something that can be tested with `rustc_dump_vtable`, since having multiple supertraits that are identical is a recipe for ambiguity errors. Maybe someone else is more creative with getting that attr to work, since the tests I added being run-pass tests is a bit unsatisfying. Miri also doesn't help here, since it doesn't really generate vtables that are offset by an index in the same way as codegen. r? `@lcnr` for the vibe check? Or reassign, idk. Maybe let's talk about whether this makes sense. <sup>(I guess an alternative would also be to not do any deduplication of vtable supertraits (or only a really conservative subset) rather than trying to normalize and deduplicate more faithfully here. Not sure if that works and is sufficient tho.)</sup> cc `@steffahn` -- ty for the minimizations cc `@WaffleLapkin` -- since you're overseeing the feature stabilization :3 Fixes #135315 Fixes #135316
2025-01-30Auto merge of #136318 - matthiaskrgr:rollup-a159mzo, r=matthiaskrgrbors-22/+156
Rollup of 9 pull requests Successful merges: - #135026 (Cast global variables to default address space) - #135475 (uefi: Implement path) - #135852 (Add `AsyncFn*` to `core` prelude) - #136004 (tests: Skip const OOM tests on aarch64-unknown-linux-gnu) - #136157 (override build profile for bootstrap tests) - #136180 (Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value) - #136256 (Add release notes for 1.84.1) - #136271 (Remove minor future footgun in `impl Debug for MaybeUninit`) - #136288 (Improve documentation for file locking) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-30Rollup merge of #136180 - lukas-code:typed-valtree, r=oli-obkMatthias Krüger-1/+1
Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value This PR adds a new wrapper type `ty::Value` to replace the tuple `(Ty, ty::ValTree)` and become the new canonical representation of type-level constant values. The value extraction methods `try_to_bits`/`try_to_bool`/`try_to_target_usize` are moved to this new type. For `try_to_bits` in particular, this avoids some redundant matches on `ty::ConstKind::Value`. Furthermore, these methods and will now properly check the type before extracting the value, which fixes some ICEs. The name `ty::Value` was chosen to be consistent with `ty::Expr`. Commit 1 should be non-functional and commit 2 adds the type check. --- fixes https://github.com/rust-lang/rust/issues/131102 supercedes https://github.com/rust-lang/rust/pull/136130 r? `@oli-obk` cc `@FedericoBruzzone` `@BoxyUwU`
2025-01-30Rollup merge of #135026 - Flakebi:global-addrspace, r=saethlinMatthias Krüger-21/+155
Cast global variables to default address space Pointers for variables all need to be in the same address space for correct compilation. Therefore ensure that even if a global variable is created in a different address space, it is casted to the default address space before its value is used. This is necessary for the amdgpu target and others where the default address space for global variables is not 0. For example `core` does not compile in debug mode when not casting the address space to the default one because it tries to emit the following (simplified) LLVM IR, containing a type mismatch: ```llvm `@alloc_0` = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1 `@alloc_1` = addrspace(1) constant <{ ptr }> <{ ptr addrspace(1) `@alloc_0` }>, align 8 ; ^ here a struct containing a `ptr` is needed, but it is created using a `ptr addrspace(1)` ``` For this to compile, we need to insert a constant `addrspacecast` before we use a global variable: ```llvm `@alloc_0` = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1 `@alloc_1` = addrspace(1) constant <{ ptr }> <{ ptr addrspacecast (ptr addrspace(1) `@alloc_0` to ptr) }>, align 8 ``` As vtables are global variables as well, they are also created with an `addrspacecast`. In the SSA backend, after a vtable global is created, metadata is added to it. To add metadata, we need the non-casted global variable. Therefore we strip away an addrspacecast if there is one, to get the underlying global. Tracking issue: #135024
2025-01-30introduce `ty::Value`Lukas Markeffsky-1/+1
Co-authored-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2025-01-30Use ExistentialTraitRef throughout codegenMichael Goulet-15/+13
2025-01-30Do not treat vtable supertraits as distinct when bound with different bound varsMichael Goulet-2/+7
2025-01-29Clean up uses of the unstable `dwarf_version` optionWesley Wiser-25/+27
- Consolidate calculation of the effective value. - Check the target `DebuginfoKind` instead of using `is_like_msvc`.
2025-01-29upstream rustc_codegen_ssa/rustc_middle changes for enzyme/autodiffManuel Drehwald-9/+11