File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,55 @@ pub fn option_none_init() -> [Option<u8>; N] {
8989 [ const { None } ; N ]
9090}
9191
92+ // If there is partial provenance or some bytes are initialized and some are not,
93+ // we can't really do better than initialize bytes or groups of bytes together.
94+ // CHECK-LABEL: @option_maybe_uninit_init
95+ #[ no_mangle]
96+ pub fn option_maybe_uninit_init ( ) -> [ MaybeUninit < u16 > ; N ] {
97+ // CHECK-NOT: select
98+ // CHECK: br label %repeat_loop_header{{.*}}
99+ // CHECK-NOT: switch
100+ // CHECK: icmp
101+ // CHECK-NOT: call void @llvm.memset.p0
102+ [ const {
103+ let mut val: MaybeUninit < u16 > = MaybeUninit :: uninit ( ) ;
104+ let ptr = val. as_mut_ptr ( ) as * mut u8 ;
105+ unsafe {
106+ ptr. write ( 0 ) ;
107+ }
108+ val
109+ } ; N ]
110+ }
111+
112+ #[ repr( packed) ]
113+ struct Packed {
114+ start : u8 ,
115+ ptr : & ' static ( ) ,
116+ rest : u16 ,
117+ rest2 : u8 ,
118+ }
119+
120+ // If there is partial provenance or some bytes are initialized and some are not,
121+ // we can't really do better than initialize bytes or groups of bytes together.
122+ // CHECK-LABEL: @option_maybe_uninit_provenance
123+ #[ no_mangle]
124+ pub fn option_maybe_uninit_provenance ( ) -> [ MaybeUninit < Packed > ; N ] {
125+ // CHECK-NOT: select
126+ // CHECK: br label %repeat_loop_header{{.*}}
127+ // CHECK-NOT: switch
128+ // CHECK: icmp
129+ // CHECK-NOT: call void @llvm.memset.p0
130+ [ const {
131+ let mut val: MaybeUninit < Packed > = MaybeUninit :: uninit ( ) ;
132+ unsafe {
133+ let ptr = & raw mut ( * val. as_mut_ptr ( ) ) . ptr ;
134+ static HAS_ADDR : ( ) = ( ) ;
135+ ptr. write_unaligned ( & HAS_ADDR ) ;
136+ }
137+ val
138+ } ; N ]
139+ }
140+
92141// Use an opaque function to prevent rustc from removing useless drops.
93142#[ inline( never) ]
94143pub fn opaque ( _: impl Sized ) { }
You can’t perform that action at this time.
0 commit comments