2021-03-31 04:06:01 +00:00
|
|
|
// compile-flags: -C no-prepopulate-passes
|
|
|
|
|
|
|
|
// Check that we use undef (and not zero) for uninitialized bytes in constants.
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
use std::mem::MaybeUninit;
|
|
|
|
|
|
|
|
pub struct PartiallyUninit {
|
|
|
|
x: u32,
|
2023-05-15 19:15:28 +00:00
|
|
|
y: MaybeUninit<[u8; 10]>,
|
2021-03-31 04:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: [[FULLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [10 x i8] }> undef
|
2022-02-18 20:57:10 +00:00
|
|
|
|
2022-12-06 17:12:46 +00:00
|
|
|
// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"{{\\EF\\BE\\AD\\DE|\\DE\\AD\\BE\\EF}}", [12 x i8] undef }>, align 4
|
2022-02-18 20:57:10 +00:00
|
|
|
|
2022-02-19 15:35:44 +00:00
|
|
|
// This shouldn't contain undef, since it contains more chunks
|
|
|
|
// than the default value of uninit_const_chunk_threshold.
|
2022-02-18 20:57:10 +00:00
|
|
|
// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4
|
|
|
|
|
2021-03-31 04:06:01 +00:00
|
|
|
// CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef
|
|
|
|
|
|
|
|
// CHECK-LABEL: @fully_uninit
|
|
|
|
#[no_mangle]
|
|
|
|
pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> {
|
|
|
|
const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit();
|
2023-05-15 19:15:28 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 1 %_0, ptr align 1 {{.*}}[[FULLY_UNINIT]]{{.*}}, i{{(32|64)}} 10, i1 false)
|
2021-03-31 04:06:01 +00:00
|
|
|
M
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @partially_uninit
|
|
|
|
#[no_mangle]
|
|
|
|
pub const fn partially_uninit() -> PartiallyUninit {
|
|
|
|
const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() };
|
2023-05-15 19:15:28 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}[[PARTIALLY_UNINIT]]{{.*}}, i{{(32|64)}} 16, i1 false)
|
2022-02-18 20:57:10 +00:00
|
|
|
X
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @uninit_padding_huge
|
|
|
|
#[no_mangle]
|
|
|
|
pub const fn uninit_padding_huge() -> [(u32, u8); 4096] {
|
|
|
|
const X: [(u32, u8); 4096] = [(123, 45); 4096];
|
2023-05-15 19:15:28 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}[[UNINIT_PADDING_HUGE]]{{.*}}, i{{(32|64)}} 32768, i1 false)
|
2021-03-31 04:06:01 +00:00
|
|
|
X
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @fully_uninit_huge
|
|
|
|
#[no_mangle]
|
|
|
|
pub const fn fully_uninit_huge() -> MaybeUninit<[u32; 4096]> {
|
|
|
|
const F: MaybeUninit<[u32; 4096]> = MaybeUninit::uninit();
|
2023-05-15 19:15:28 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}[[FULLY_UNINIT_HUGE]]{{.*}}, i{{(32|64)}} 16384, i1 false)
|
2021-03-31 04:06:01 +00:00
|
|
|
F
|
|
|
|
}
|