Add a MIR test for align_of_val on a slice

This commit is contained in:
Scott McMurray
2025-07-27 23:23:22 -07:00
parent 950a3b34ea
commit 185b074518
2 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
- // MIR for `of_val_slice` before InstSimplify-after-simplifycfg
+ // MIR for `of_val_slice` after InstSimplify-after-simplifycfg
fn of_val_slice(_1: &[T]) -> usize {
debug slice => _1;
let mut _0: usize;
let mut _2: *const [T];
bb0: {
StorageLive(_2);
_2 = &raw const (*_1);
_0 = std::intrinsics::align_of_val::<[T]>(move _2) -> [return: bb1, unwind unreachable];
}
bb1: {
StorageDead(_2);
return;
}
}

View File

@@ -0,0 +1,13 @@
//@ test-mir-pass: InstSimplify-after-simplifycfg
//@ needs-unwind
#![crate_type = "lib"]
#![feature(core_intrinsics)]
// EMIT_MIR align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff
pub fn of_val_slice<T>(slice: &[T]) -> usize {
// CHECK-LABEL: fn of_val_slice(_1: &[T])
// CHECK: _2 = &raw const (*_1);
// CHECK: _0 = std::intrinsics::align_of_val::<[T]>(move _2)
unsafe { core::intrinsics::align_of_val(slice) }
}