rust/compiler/rustc_codegen_ssa/src
bors e9acbd99d3 Auto merge of #147827 - saethlin:maybeuninit-codegen2, r=scottmcm
Fix MaybeUninit codegen using GVN

This is an alternative to https://github.com/rust-lang/rust/pull/142837, based on https://github.com/rust-lang/rust/pull/146355#discussion_r2421651968.

The general approach I took here is to aggressively propagate anything that is entirely uninitialized. GVN generally takes the approach of only synthesizing small types, but we need to generate large consts to fix the codegen issue.

I also added a special case to MIR dumps for this where now an entirely uninit const is printed as `const <uninit>`, because otherwise we end up with extremely verbose dumps of the new consts.

After GVN though, we still end up with a lot of MIR that looks like this:
```
StorageLive(_1);
_1 = const <uninit>;
_2 = &raw mut _1;
```
Which will break tests/codegen-llvm/maybeuninit-rvo.rs with the naive lowering. I think the ideal fix here is to somehow omit these `_1 = const <uninit>` assignments that come directly after a StorageLive, but I'm not sure how to do that. For now at least, ignoring such assignments (even if they don't come right after a StorageLive) in codegen seems to work.

Note that since GVN is based on synthesizing a `ConstValue`  which has a defined layout, this scenario still gets deoptimized by LLVM.
```rust
#![feature(rustc_attrs)]
#![crate_type = "lib"]
use std::mem::MaybeUninit;

#[unsafe(no_mangle)]
pub fn oof() -> [[MaybeUninit<u8>; 8]; 8] {
    #[rustc_no_mir_inline]
    pub fn inner<T: Copy>() -> [[MaybeUninit<T>; 8]; 8] {
        [[MaybeUninit::uninit(); 8]; 8]
    }

    inner()
}
```
This case can be handled correctly if enough inlining has happened, or it could be handled by post-mono GVN. Synthesizing `UnevaluatedConst` or some other special kind of const seems dubious.
2025-11-23 17:09:07 +00:00
..
back Allow passing primary spans to SharedEmitter 2025-11-21 14:37:10 +00:00
debuginfo Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
mir Auto merge of #147827 - saethlin:maybeuninit-codegen2, r=scottmcm 2025-11-23 17:09:07 +00:00
traits Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
assert_module_sources.rs Print CGU reuse statistics when -Zprint-mono-items is enabled 2025-08-04 15:43:50 +02:00
base.rs rustc_target: introduce Os 2025-11-11 18:55:40 -05:00
codegen_attrs.rs Rollup merge of #148839 - luca3s:rtsan_ice_fix, r=WaffleLapkin 2025-11-13 11:57:08 +11:00
common.rs rustc_target: introduce Os 2025-11-11 18:55:40 -05:00
errors.rs Fix double error for #[no_mangle] on closures 2025-10-08 17:46:33 +02:00
lib.rs Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
meth.rs Remove DynKind 2025-09-17 04:46:46 +02:00
mono_item.rs Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
size_of_val.rs remove explicit deref of AbiAlign for most methods 2025-09-28 15:02:14 -07:00
target_features.rs Auto merge of #148516 - bjorn3:target_feature_parsing_improvements, r=WaffleLapkin 2025-11-05 17:56:16 +00:00