2024-06-11 23:25:45 -05:00
|
|
|
//@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Z ub-checks=yes
|
2023-06-08 02:18:34 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2023-04-25 23:14:33 -05:00
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2024-04-11 19:16:28 -05:00
|
|
|
#![feature(slice_ptr_get)]
|
2023-04-25 23:14:33 -05:00
|
|
|
|
|
|
|
use std::ops::Range;
|
|
|
|
|
|
|
|
// EMIT_MIR slice_index.slice_index_usize.PreCodegen.after.mir
|
|
|
|
pub fn slice_index_usize(slice: &[u32], index: usize) -> u32 {
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-LABEL: slice_index_usize
|
|
|
|
// CHECK: [[LEN:_[0-9]+]] = Len((*_1))
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: Lt(copy _2, copy [[LEN]])
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-NOT: precondition_check
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: _0 = copy (*_1)[_2];
|
2023-04-25 23:14:33 -05:00
|
|
|
slice[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR slice_index.slice_get_mut_usize.PreCodegen.after.mir
|
|
|
|
pub fn slice_get_mut_usize(slice: &mut [u32], index: usize) -> Option<&mut u32> {
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-LABEL: slice_get_mut_usize
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: [[LEN:_[0-9]+]] = PtrMetadata(copy _1)
|
|
|
|
// CHECK: Lt(copy _2, move [[LEN]])
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-NOT: precondition_check
|
2023-04-25 23:14:33 -05:00
|
|
|
slice.get_mut(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR slice_index.slice_index_range.PreCodegen.after.mir
|
|
|
|
pub fn slice_index_range(slice: &[u32], index: Range<usize>) -> &[u32] {
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-LABEL: slice_index_range
|
2023-04-25 23:14:33 -05:00
|
|
|
&slice[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir
|
|
|
|
pub unsafe fn slice_get_unchecked_mut_range(slice: &mut [u32], index: Range<usize>) -> &mut [u32] {
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-LABEL: slice_get_unchecked_mut_range
|
|
|
|
// CHECK: [[START:_[0-9]+]] = move (_2.0: usize);
|
|
|
|
// CHECK: [[END:_[0-9]+]] = move (_2.1: usize);
|
|
|
|
// CHECK: precondition_check
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: [[LEN:_[0-9]+]] = SubUnchecked(copy [[END]], copy [[START]]);
|
|
|
|
// CHECK: [[PTR:_[0-9]+]] = Offset(copy {{_[0-9]+}}, copy [[START]]);
|
|
|
|
// CHECK: [[SLICE:_[0-9]+]] = *mut [u32] from (copy [[PTR]], copy [[LEN]])
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK: _0 = &mut (*[[SLICE]]);
|
2023-04-25 23:14:33 -05:00
|
|
|
slice.get_unchecked_mut(index)
|
|
|
|
}
|
2024-04-11 19:16:28 -05:00
|
|
|
|
|
|
|
// EMIT_MIR slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.mir
|
|
|
|
pub unsafe fn slice_ptr_get_unchecked_range(
|
|
|
|
slice: *const [u32],
|
|
|
|
index: Range<usize>,
|
|
|
|
) -> *const [u32] {
|
2024-06-11 23:26:41 -05:00
|
|
|
// CHECK-LABEL: slice_ptr_get_unchecked_range
|
|
|
|
// CHECK: [[START:_[0-9]+]] = move (_2.0: usize);
|
|
|
|
// CHECK: [[END:_[0-9]+]] = move (_2.1: usize);
|
|
|
|
// CHECK: precondition_check
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: [[LEN:_[0-9]+]] = SubUnchecked(copy [[END]], copy [[START]]);
|
|
|
|
// CHECK: [[PTR:_[0-9]+]] = Offset(copy {{_[0-9]+}}, copy [[START]]);
|
|
|
|
// CHECK: _0 = *const [u32] from (copy [[PTR]], copy [[LEN]])
|
2024-04-11 19:16:28 -05:00
|
|
|
slice.get_unchecked(index)
|
|
|
|
}
|