]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/uninit-consts-allow-partially-uninit.rs
Rollup merge of #88659 - est31:update_smallvec_name, r=matthewjasper
[rust.git] / src / test / codegen / uninit-consts-allow-partially-uninit.rs
1 // compile-flags: -C no-prepopulate-passes -Z partially_uninit_const_threshold=1024
2
3 // Like uninit-consts.rs, but tests that we correctly generate partially-uninit consts
4 // when the (disabled by default) partially_uninit_const_threshold flag is used.
5
6 #![crate_type = "lib"]
7
8 use std::mem::MaybeUninit;
9
10 pub struct PartiallyUninit {
11     x: u32,
12     y: MaybeUninit<[u8; 10]>
13 }
14
15 // This should be partially undef.
16 // CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4
17
18 // This shouldn't contain undef, since it's larger than the 1024 byte limit.
19 // CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4
20
21 // CHECK-LABEL: @partially_uninit
22 #[no_mangle]
23 pub const fn partially_uninit() -> PartiallyUninit {
24     const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() };
25     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [12 x i8] }>, <{ [4 x i8], [12 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false)
26     X
27 }
28
29 // CHECK-LABEL: @uninit_padding_huge
30 #[no_mangle]
31 pub const fn uninit_padding_huge() -> [(u32, u8); 4096] {
32     const X: [(u32, u8); 4096] = [(123, 45); 4096];
33     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [32768 x i8] }>, <{ [32768 x i8] }>* [[UNINIT_PADDING_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 32768, i1 false)
34     X
35 }