Skip to content

Commit 8f5f5e5

Browse files
committed
Add more tests
1 parent dfa4c01 commit 8f5f5e5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/codegen/slice-init.rs

+49
Original file line numberDiff line numberDiff 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)]
94143
pub fn opaque(_: impl Sized) {}

0 commit comments

Comments
 (0)