diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-03 20:47:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-03 20:47:12 +0100 |
| commit | 70b9968d1ea5d257d8f3cfa17d3847d2266199df (patch) | |
| tree | 039526c8beb9cd8526c733fd60c7e5e514e8829b /tests/codegen | |
| parent | a4b61811564307efc7d49fc2ca8c154021f36b1c (diff) | |
| parent | 5f575bc4bca3f18e4798110b05e059a840c0fd49 (diff) | |
| download | rust-70b9968d1ea5d257d8f3cfa17d3847d2266199df.tar.gz rust-70b9968d1ea5d257d8f3cfa17d3847d2266199df.zip | |
Rollup merge of #137894 - compiler-errors:no-scalar-pair-opt, r=oli-obk
Revert "store ScalarPair via memset when one side is undef and the other side can be memset" cc #137892 reverts #135335 r? oli-obk
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/slice-init.rs | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/tests/codegen/slice-init.rs b/tests/codegen/slice-init.rs index b36a5b5de3d..950e0b0c10d 100644 --- a/tests/codegen/slice-init.rs +++ b/tests/codegen/slice-init.rs @@ -2,8 +2,6 @@ #![crate_type = "lib"] -use std::mem::MaybeUninit; - // CHECK-LABEL: @zero_sized_elem #[no_mangle] pub fn zero_sized_elem() { @@ -78,64 +76,31 @@ pub fn u16_init_one_bytes() -> [u16; N] { [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-NOT: br - // CHECK-NOT: switch - // CHECK-NOT: icmp - // CHECK: call void @llvm.memset.p0 - [const { None }; N] -} - -// If there is partial provenance or some bytes are initialized and some are not, -// we can't really do better than initialize bytes or groups of bytes together. -// CHECK-LABEL: @option_maybe_uninit_init -#[no_mangle] -pub fn option_maybe_uninit_init() -> [MaybeUninit<u16>; N] { - // CHECK-NOT: select // CHECK: br label %repeat_loop_header{{.*}} // CHECK-NOT: switch // CHECK: icmp // CHECK-NOT: call void @llvm.memset.p0 - [const { - let mut val: MaybeUninit<u16> = MaybeUninit::uninit(); - let ptr = val.as_mut_ptr() as *mut u8; - unsafe { - ptr.write(0); - } - val - }; N] + [None; N] } -#[repr(packed)] -struct Packed { - start: u8, - ptr: &'static (), - rest: u16, - rest2: u8, -} +use std::mem::MaybeUninit; -// If there is partial provenance or some bytes are initialized and some are not, -// we can't really do better than initialize bytes or groups of bytes together. -// CHECK-LABEL: @option_maybe_uninit_provenance +// FIXME: This could be optimized into a memset. +// Regression test for <https://github.com/rust-lang/rust/issues/137892>. #[no_mangle] -pub fn option_maybe_uninit_provenance() -> [MaybeUninit<Packed>; N] { +pub fn half_uninit() -> [(u128, MaybeUninit<u128>); N] { // CHECK-NOT: select // CHECK: br label %repeat_loop_header{{.*}} // CHECK-NOT: switch // CHECK: icmp // CHECK-NOT: call void @llvm.memset.p0 - [const { - let mut val: MaybeUninit<Packed> = MaybeUninit::uninit(); - unsafe { - let ptr = &raw mut (*val.as_mut_ptr()).ptr; - static HAS_ADDR: () = (); - ptr.write_unaligned(&HAS_ADDR); - } - val - }; N] + [const { (0, MaybeUninit::uninit()) }; N] } // Use an opaque function to prevent rustc from removing useless drops. |
