1
Fork 0

Add regression test for option initialization

This commit is contained in:
Oli Scherer 2025-01-08 14:21:40 +00:00
parent 88ab2d8acb
commit aec51564a5

View file

@ -63,6 +63,34 @@ pub fn nonzero_integer_array() {
opaque(&x); opaque(&x);
} }
const N: usize = 100;
// FIXME: The two bytes of the u16 are the same, so we should
// just use memset, too.
// CHECK-LABEL: @u16_init_one_bytes
#[no_mangle]
pub fn u16_init_one_bytes() -> [u16; N] {
// CHECK-NOT: select
// CHECK: br
// CHECK-NOT: switch
// CHECK: icmp
// CHECK-NOT: call void @llvm.memset.p0
[const { u16::from_be_bytes([1, 1]) }; N]
}
// FIXME: undef bytes can just be initialized with the same value as the
// defined bytes, if the defines bytes are all the same.
// CHECK-LABEL: @option_none_init
#[no_mangle]
pub fn option_none_init() -> [Option<u8>; N] {
// CHECK-NOT: select
// CHECK: br label %repeat_loop_header{{.*}}
// CHECK-NOT: switch
// CHECK: icmp
// CHECK-NOT: call void @llvm.memset.p0
[None; N]
}
// Use an opaque function to prevent rustc from removing useless drops. // Use an opaque function to prevent rustc from removing useless drops.
#[inline(never)] #[inline(never)]
pub fn opaque(_: impl Sized) {} pub fn opaque(_: impl Sized) {}