Skip to content

Commit aec5156

Browse files
committed
Add regression test for option initialization
1 parent 88ab2d8 commit aec5156

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/codegen/slice-init.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ pub fn nonzero_integer_array() {
6363
opaque(&x);
6464
}
6565

66+
const N: usize = 100;
67+
68+
// FIXME: The two bytes of the u16 are the same, so we should
69+
// just use memset, too.
70+
// CHECK-LABEL: @u16_init_one_bytes
71+
#[no_mangle]
72+
pub fn u16_init_one_bytes() -> [u16; N] {
73+
// CHECK-NOT: select
74+
// CHECK: br
75+
// CHECK-NOT: switch
76+
// CHECK: icmp
77+
// CHECK-NOT: call void @llvm.memset.p0
78+
[const { u16::from_be_bytes([1, 1]) }; N]
79+
}
80+
81+
// FIXME: undef bytes can just be initialized with the same value as the
82+
// defined bytes, if the defines bytes are all the same.
83+
// CHECK-LABEL: @option_none_init
84+
#[no_mangle]
85+
pub fn option_none_init() -> [Option<u8>; N] {
86+
// CHECK-NOT: select
87+
// CHECK: br label %repeat_loop_header{{.*}}
88+
// CHECK-NOT: switch
89+
// CHECK: icmp
90+
// CHECK-NOT: call void @llvm.memset.p0
91+
[None; N]
92+
}
93+
6694
// Use an opaque function to prevent rustc from removing useless drops.
6795
#[inline(never)]
6896
pub fn opaque(_: impl Sized) {}

0 commit comments

Comments
 (0)