mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 09:44:40 +00:00
MIR GVN propagates MaybeUninit::uninit() as `const <uninit>` in aggregate constructions and codegen emits a memcpy from an `[N x i8] undef` global for each such field, which LLVM materializes as zero-initialization. Instead of special-casing `all_bytes_uninit` at each call site, add a new `OperandValue::Uninit` variant that `eval_mir_constant_to_operand` returns for any all-bytes-uninit constant. `store_with_flags` is a no-op for this variant, so the fix applies uniformly across `Rvalue::Use`, `Rvalue::Repeat`, and `Rvalue::Aggregate` without per-site checks. The variant propagates through field extraction and transmutes, and is handled appropriately at the remaining call sites (function arguments, discriminant reads, debug info, etc.).
31 lines
992 B
Rust
31 lines
992 B
Rust
// Regression test for https://github.com/rust-lang/rust/issues/157743
|
|
//
|
|
// At opt-level >= 1, MIR GVN inlines MaybeUninit::uninit() and propagates the
|
|
// result as `const <uninit>` in aggregate constructions. Without the fix, this
|
|
// caused codegen to emit a memcpy from an `[N x i8] undef` global constant for
|
|
// the uninit field, which LLVM would materialize as zero-initialization.
|
|
//
|
|
// The fix skips emitting any IR for entirely-uninit constant aggregate fields.
|
|
|
|
//@ compile-flags: -C no-prepopulate-passes -C opt-level=2
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
use std::mem::MaybeUninit;
|
|
|
|
pub struct Inner {
|
|
cap: usize,
|
|
data: MaybeUninit<[u64; 2]>,
|
|
}
|
|
|
|
// CHECK-LABEL: @make_inner
|
|
// The non-uninit field must be stored.
|
|
// CHECK: store i{{(32|64)}}
|
|
// The entirely-uninit `data` field must not cause a memcpy from an undef global.
|
|
// CHECK-NOT: call void @llvm.memcpy
|
|
// CHECK: ret void
|
|
#[no_mangle]
|
|
pub fn make_inner(cap: usize) -> Inner {
|
|
Inner { cap, data: MaybeUninit::uninit() }
|
|
}
|