Skip to content

Commit

Permalink
Add regression test for option initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 10, 2025
1 parent 88ab2d8 commit aec5156
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/codegen/slice-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ pub fn nonzero_integer_array() {
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.
#[inline(never)]
pub fn opaque(_: impl Sized) {}

0 comments on commit aec5156

Please sign in to comment.