]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/uninit-consts.rs
Do not suggest using a const parameter when there are bounds on an unused type parameter
[rust.git] / src / test / codegen / uninit-consts.rs
1 // compile-flags: -C no-prepopulate-passes
2
3 // Check that we use undef (and not zero) for uninitialized bytes in constants.
4
5 #![crate_type = "lib"]
6
7 use std::mem::MaybeUninit;
8
9 pub struct PartiallyUninit {
10     x: u32,
11     y: MaybeUninit<[u8; 10]>
12 }
13
14 // CHECK: [[FULLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [10 x i8] }> undef
15 // CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [16 x i8] }> <{ [16 x i8] c"\EF\BE\AD\DE\00\00\00\00\00\00\00\00\00\00\00\00" }>, align 4
16 // CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef
17
18 // CHECK-LABEL: @fully_uninit
19 #[no_mangle]
20 pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> {
21     const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit();
22     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 1 %1, i8* align 1 getelementptr inbounds (<{ [10 x i8] }>, <{ [10 x i8] }>* [[FULLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 10, i1 false)
23     M
24 }
25
26 // CHECK-LABEL: @partially_uninit
27 #[no_mangle]
28 pub const fn partially_uninit() -> PartiallyUninit {
29     const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() };
30     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [16 x i8] }>, <{ [16 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false)
31     X
32 }
33
34 // CHECK-LABEL: @fully_uninit_huge
35 #[no_mangle]
36 pub const fn fully_uninit_huge() -> MaybeUninit<[u32; 4096]> {
37     const F: MaybeUninit<[u32; 4096]> = MaybeUninit::uninit();
38     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [16384 x i8] }>, <{ [16384 x i8] }>* [[FULLY_UNINIT_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 16384, i1 false)
39     F
40 }