From 8bcfc0e597294f48549ed446f89415150516d030 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 25 Apr 2023 21:14:33 -0700 Subject: [PATCH 1/2] Add some MIR pre-codegen tests for slice indexing --- tests/mir-opt/pre-codegen/slice_index.rs | 27 ++++ ...x.slice_get_mut_usize.PreCodegen.after.mir | 123 ++++++++++++++ ...t_unchecked_mut_range.PreCodegen.after.mir | 152 ++++++++++++++++++ ...dex.slice_index_range.PreCodegen.after.mir | 26 +++ ...dex.slice_index_usize.PreCodegen.after.mir | 20 +++ 5 files changed, 348 insertions(+) create mode 100644 tests/mir-opt/pre-codegen/slice_index.rs create mode 100644 tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir create mode 100644 tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir create mode 100644 tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.mir create mode 100644 tests/mir-opt/pre-codegen/slice_index.slice_index_usize.PreCodegen.after.mir diff --git a/tests/mir-opt/pre-codegen/slice_index.rs b/tests/mir-opt/pre-codegen/slice_index.rs new file mode 100644 index 0000000000000..44b45627607ef --- /dev/null +++ b/tests/mir-opt/pre-codegen/slice_index.rs @@ -0,0 +1,27 @@ +// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 +// only-64bit +// ignore-debug + +#![crate_type = "lib"] + +use std::ops::Range; + +// EMIT_MIR slice_index.slice_index_usize.PreCodegen.after.mir +pub fn slice_index_usize(slice: &[u32], index: usize) -> u32 { + 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> { + slice.get_mut(index) +} + +// EMIT_MIR slice_index.slice_index_range.PreCodegen.after.mir +pub fn slice_index_range(slice: &[u32], index: Range) -> &[u32] { + &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) -> &mut [u32] { + slice.get_unchecked_mut(index) +} diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir new file mode 100644 index 0000000000000..1f15b774cae79 --- /dev/null +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir @@ -0,0 +1,123 @@ +// MIR for `slice_get_mut_usize` after PreCodegen + +fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { + debug slice => _1; // in scope 0 at $DIR/slice_index.rs:+0:28: +0:33 + debug index => _2; // in scope 0 at $DIR/slice_index.rs:+0:47: +0:52 + let mut _0: std::option::Option<&mut u32>; // return place in scope 0 at $DIR/slice_index.rs:+0:64: +0:80 + scope 1 (inlined core::slice::::get_mut::) { // at $DIR/slice_index.rs:16:11: 16:25 + debug self => _1; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + debug index => _2; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + scope 2 (inlined >::get_mut) { // at $SRC_DIR/core/src/slice/mod.rs:LL:COL + debug self => _2; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug slice => _1; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _3: bool; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _4: usize; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _5: &[u32]; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _6: &mut u32; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _7: *mut u32; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _8: *mut [u32]; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + scope 3 { + scope 4 (inlined >::get_unchecked_mut) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _2; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug slice => _8; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _9: *mut u32; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _10: usize; // in scope 4 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + let mut _11: *mut [u32]; // in scope 4 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + scope 5 { + debug this => _2; // in scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + scope 6 { + scope 7 (inlined >::get_unchecked_mut::runtime::) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL + debug this => _10; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + debug slice => _11; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + scope 8 (inlined ptr::mut_ptr::::len) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _11; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _12: *const [u32]; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 9 (inlined std::ptr::metadata::<[u32]>) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug ptr => _12; // in scope 9 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + scope 10 { + } + } + } + } + scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _8; // in scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + } + scope 12 (inlined ptr::mut_ptr::::add) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _9; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug count => _2; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _13: isize; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 13 { + scope 14 (inlined ptr::mut_ptr::::offset) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug self => _9; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug count => _13; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _14: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _15: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 15 { + } + } + } + } + } + } + } + } + } + } + + bb0: { + StorageLive(_6); // scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_3); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_5); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _5 = &(*_1); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _4 = Len((*_5)); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_5); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _3 = Lt(_2, move _4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + switchInt(move _3) -> [0: bb2, otherwise: bb1]; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + } + + bb1: { + StorageLive(_7); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_8); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _8 = &raw mut (*_1); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_10); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _9 = _8 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _13 = _2 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _14 = Offset(move _15, _13); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_10); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_8); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _6 = &mut (*_7); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _0 = Option::<&mut u32>::Some(_6); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_7); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + goto -> bb3; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + } + + bb2: { + _0 = const Option::<&mut u32>::None; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + // mir::Constant + // + span: no-location + // + literal: Const { ty: Option<&mut u32>, val: Value(Scalar(0x0000000000000000)) } + goto -> bb3; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + } + + bb3: { + StorageDead(_3); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_6); // scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + return; // scope 0 at $DIR/slice_index.rs:+2:2: +2:2 + } +} diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir new file mode 100644 index 0000000000000..8b509290866eb --- /dev/null +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir @@ -0,0 +1,152 @@ +// MIR for `slice_get_unchecked_mut_range` after PreCodegen + +fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> &mut [u32] { + debug slice => _1; // in scope 0 at $DIR/slice_index.rs:+0:45: +0:50 + debug index => _2; // in scope 0 at $DIR/slice_index.rs:+0:64: +0:69 + let mut _0: &mut [u32]; // return place in scope 0 at $DIR/slice_index.rs:+1:5: +1:35 + scope 1 (inlined core::slice::::get_unchecked_mut::>) { // at $DIR/slice_index.rs:26:11: 26:35 + debug self => _1; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + debug index => _2; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + let mut _3: *mut [u32]; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + let mut _4: *mut [u32]; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + scope 2 { + scope 3 (inlined as SliceIndex<[u32]>>::get_unchecked_mut) { // at $SRC_DIR/core/src/slice/mod.rs:LL:COL + debug self => _2; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug slice => _4; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let _5: std::ops::Range; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _7: usize; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _8: usize; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _9: *mut u32; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _10: *mut u32; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _11: usize; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _12: usize; // in scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL + let mut _13: std::ops::Range; // in scope 3 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + let mut _14: *mut [u32]; // in scope 3 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + scope 4 { + debug this => _5; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL + scope 5 { + let _6: usize; // in scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + scope 6 { + debug new_len => _6; // in scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _4; // in scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + } + scope 12 (inlined ptr::mut_ptr::::add) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _10; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug count => _11; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _16: isize; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 13 { + scope 14 (inlined ptr::mut_ptr::::offset) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug self => _10; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug count => _16; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _17: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _18: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 15 { + } + } + } + } + scope 16 (inlined slice_from_raw_parts_mut::) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug data => _9; // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug len => _12; // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + let mut _19: *mut (); // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + scope 17 (inlined ptr::mut_ptr::::cast::<()>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug self => _9; // in scope 17 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + } + scope 18 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug data_address => _19; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + debug metadata => _12; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _20: std::ptr::metadata::PtrRepr<[u32]>; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _21: std::ptr::metadata::PtrComponents<[u32]>; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _22: *const (); // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + scope 19 { + } + } + } + } + scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL + debug this => _13; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + debug slice => _14; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL + scope 8 (inlined ptr::mut_ptr::::len) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug self => _14; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + let mut _15: *const [u32]; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 9 (inlined std::ptr::metadata::<[u32]>) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + debug ptr => _15; // in scope 9 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + scope 10 { + } + } + } + } + } + } + } + } + } + + bb0: { + StorageLive(_3); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_4); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + _4 = &raw mut (*_1); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_5); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_13); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_14); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_15); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageLive(_6); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_7); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _7 = (_2.1: usize); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_8); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _8 = (_2.0: usize); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _6 = unchecked_sub::(move _7, move _8) -> [return: bb1, unwind unreachable]; // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + // mir::Constant + // + span: $SRC_DIR/core/src/slice/index.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(usize, usize) -> usize {unchecked_sub::}, val: Value() } + } + + bb1: { + StorageDead(_8); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_7); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_10); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _10 = _4 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_11); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _11 = (_2.0: usize); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_16); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _16 = _11 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_17); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_18); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _18 = _10 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _17 = Offset(move _18, _16); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_18); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _9 = move _17 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_17); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_16); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageDead(_11); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_10); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_12); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + _12 = _6; // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageLive(_19); // scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + _19 = _9 as *mut () (PtrToPtr); // scope 17 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_20); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageLive(_21); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageLive(_22); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _22 = _19 as *const () (Pointer(MutToConstPointer)); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _21 = ptr::metadata::PtrComponents::<[u32]> { data_address: move _22, metadata: _12 }; // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_22); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _20 = ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _21 }; // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_21); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _3 = (_20.1: *mut [u32]); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_20); // scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_19); // scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + StorageDead(_12); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_6); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL + StorageDead(_15); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageDead(_14); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageDead(_13); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageDead(_5); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageDead(_4); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + _0 = &mut (*_3); // scope 2 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + StorageDead(_3); // scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL + return; // scope 0 at $DIR/slice_index.rs:+2:2: +2:2 + } +} diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.mir new file mode 100644 index 0000000000000..35dd973b55fa1 --- /dev/null +++ b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.mir @@ -0,0 +1,26 @@ +// MIR for `slice_index_range` after PreCodegen + +fn slice_index_range(_1: &[u32], _2: std::ops::Range) -> &[u32] { + debug slice => _1; // in scope 0 at $DIR/slice_index.rs:+0:26: +0:31 + debug index => _2; // in scope 0 at $DIR/slice_index.rs:+0:41: +0:46 + let mut _0: &[u32]; // return place in scope 0 at $DIR/slice_index.rs:+1:5: +1:18 + let _3: &[u32]; // in scope 0 at $DIR/slice_index.rs:+1:6: +1:18 + scope 1 (inlined #[track_caller] core::slice::index::> for [u32]>::index) { // at $DIR/slice_index.rs:21:6: 21:18 + debug self => _1; // in scope 1 at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug index => _2; // in scope 1 at $SRC_DIR/core/src/slice/index.rs:LL:COL + } + + bb0: { + StorageLive(_3); // scope 0 at $DIR/slice_index.rs:+1:6: +1:18 + _3 = as SliceIndex<[u32]>>::index(move _2, _1) -> bb1; // scope 1 at $SRC_DIR/core/src/slice/index.rs:LL:COL + // mir::Constant + // + span: $SRC_DIR/core/src/slice/index.rs:LL:COL + // + literal: Const { ty: for<'a> fn(std::ops::Range, &'a [u32]) -> &'a as SliceIndex<[u32]>>::Output { as SliceIndex<[u32]>>::index}, val: Value() } + } + + bb1: { + _0 = _3; // scope 0 at $DIR/slice_index.rs:+1:5: +1:18 + StorageDead(_3); // scope 0 at $DIR/slice_index.rs:+2:1: +2:2 + return; // scope 0 at $DIR/slice_index.rs:+2:2: +2:2 + } +} diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_index_usize.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_index_usize.PreCodegen.after.mir new file mode 100644 index 0000000000000..6cc0ee0570bb5 --- /dev/null +++ b/tests/mir-opt/pre-codegen/slice_index.slice_index_usize.PreCodegen.after.mir @@ -0,0 +1,20 @@ +// MIR for `slice_index_usize` after PreCodegen + +fn slice_index_usize(_1: &[u32], _2: usize) -> u32 { + debug slice => _1; // in scope 0 at $DIR/slice_index.rs:+0:26: +0:31 + debug index => _2; // in scope 0 at $DIR/slice_index.rs:+0:41: +0:46 + let mut _0: u32; // return place in scope 0 at $DIR/slice_index.rs:+0:58: +0:61 + let mut _3: usize; // in scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + let mut _4: bool; // in scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + + bb0: { + _3 = Len((*_1)); // scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + _4 = Lt(_2, _3); // scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + assert(move _4, "index out of bounds: the length is {} but the index is {}", move _3, _2) -> bb1; // scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + } + + bb1: { + _0 = (*_1)[_2]; // scope 0 at $DIR/slice_index.rs:+1:5: +1:17 + return; // scope 0 at $DIR/slice_index.rs:+2:2: +2:2 + } +} From e1da77c76d63f442acadcfbda4e42701887d6324 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 25 Apr 2023 22:41:34 -0700 Subject: [PATCH 2/2] Also use `mir::Offset` for pointer `add` --- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 11 ++- .../rustc_hir_analysis/src/check/intrinsic.rs | 3 +- library/core/src/intrinsics.rs | 12 ++++ library/core/src/ptr/const_ptr.rs | 10 ++- library/core/src/ptr/mut_ptr.rs | 22 +++++- .../src/language-features/intrinsics.md | 2 +- tests/codegen/intrinsics/offset.rs | 34 +++++++++ ...intrinsics.ptr_offset.LowerIntrinsics.diff | 4 +- ...x.slice_get_mut_usize.PreCodegen.after.mir | 20 +----- ...t_unchecked_mut_range.PreCodegen.after.mir | 72 +++++++------------ tests/ui/const-ptr/forbidden_slices.stderr | 4 -- 11 files changed, 117 insertions(+), 77 deletions(-) create mode 100644 tests/codegen/intrinsics/offset.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 94de19a9c2935..64452472eeca4 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -819,8 +819,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .builtin_deref(true) .unwrap_or_else(|| bug!("deref of non-pointer {:?}", input_ty)) .ty; - let llty = bx.cx().backend_type(bx.cx().layout_of(pointee_type)); - bx.inbounds_gep(llty, lhs, &[rhs]) + let pointee_layout = bx.cx().layout_of(pointee_type); + if pointee_layout.is_zst() { + // `Offset` works in terms of the size of pointee, + // so offsetting a pointer to ZST is a noop. + lhs + } else { + let llty = bx.cx().backend_type(pointee_layout); + bx.inbounds_gep(llty, lhs, &[rhs]) + } } mir::BinOp::Shl => common::build_unchecked_lshift(bx, lhs, rhs), mir::BinOp::Shr => common::build_unchecked_rshift(bx, input_ty, lhs, rhs), diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 0fcbaa2efabb8..d505d8b8e0b30 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -215,7 +215,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { sym::type_name => (1, Vec::new(), tcx.mk_static_str()), sym::type_id => (1, Vec::new(), tcx.types.u64), - sym::offset | sym::arith_offset => ( + sym::offset => (2, vec![param(0), param(1)], param(0)), + sym::arith_offset => ( 1, vec![ tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 741f20cf4c715..b14c801f2fb72 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1413,6 +1413,10 @@ extern "rust-intrinsic" { /// This is implemented as an intrinsic to avoid converting to and from an /// integer, since the conversion would throw away aliasing information. /// + /// This can only be used with `Ptr` as a raw pointer type (`*mut` or `*const`) + /// to a `Sized` pointee and with `Delta` as `usize` or `isize`. Any other + /// instantiations may arbitrarily misbehave, and that's *not* a compiler bug. + /// /// # Safety /// /// Both the starting and resulting pointer must be either in bounds or one @@ -1421,6 +1425,14 @@ extern "rust-intrinsic" { /// returned value will result in undefined behavior. /// /// The stabilized version of this intrinsic is [`pointer::offset`]. + #[cfg(not(bootstrap))] + #[must_use = "returns a new pointer rather than modifying its argument"] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] + #[rustc_nounwind] + pub fn offset(dst: Ptr, offset: Delta) -> Ptr; + + /// The bootstrap version of this is more restricted. + #[cfg(bootstrap)] #[must_use = "returns a new pointer rather than modifying its argument"] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[rustc_nounwind] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 6b18f5f5a40d1..585b648873a60 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -916,8 +916,16 @@ impl *const T { where T: Sized, { + #[cfg(bootstrap)] // SAFETY: the caller must uphold the safety contract for `offset`. - unsafe { self.offset(count as isize) } + unsafe { + self.offset(count as isize) + } + #[cfg(not(bootstrap))] + // SAFETY: the caller must uphold the safety contract for `offset`. + unsafe { + intrinsics::offset(self, count) + } } /// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`). diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 7b0fd02eb9f8b..c339ccb1b4dd0 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -473,10 +473,20 @@ impl *mut T { where T: Sized, { + #[cfg(bootstrap)] // SAFETY: the caller must uphold the safety contract for `offset`. // The obtained pointer is valid for writes since the caller must // guarantee that it points to the same allocated object as `self`. - unsafe { intrinsics::offset(self, count) as *mut T } + unsafe { + intrinsics::offset(self, count) as *mut T + } + #[cfg(not(bootstrap))] + // SAFETY: the caller must uphold the safety contract for `offset`. + // The obtained pointer is valid for writes since the caller must + // guarantee that it points to the same allocated object as `self`. + unsafe { + intrinsics::offset(self, count) + } } /// Calculates the offset from a pointer in bytes. @@ -1016,8 +1026,16 @@ impl *mut T { where T: Sized, { + #[cfg(bootstrap)] + // SAFETY: the caller must uphold the safety contract for `offset`. + unsafe { + self.offset(count as isize) + } + #[cfg(not(bootstrap))] // SAFETY: the caller must uphold the safety contract for `offset`. - unsafe { self.offset(count as isize) } + unsafe { + intrinsics::offset(self, count) + } } /// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`). diff --git a/src/doc/unstable-book/src/language-features/intrinsics.md b/src/doc/unstable-book/src/language-features/intrinsics.md index a0fb4e743d3f2..ea9bace6dd47f 100644 --- a/src/doc/unstable-book/src/language-features/intrinsics.md +++ b/src/doc/unstable-book/src/language-features/intrinsics.md @@ -22,7 +22,7 @@ via a declaration like extern "rust-intrinsic" { fn transmute(x: T) -> U; - fn offset(dst: *const T, offset: isize) -> *const T; + fn arith_offset(dst: *const T, offset: isize) -> *const T; } ``` diff --git a/tests/codegen/intrinsics/offset.rs b/tests/codegen/intrinsics/offset.rs new file mode 100644 index 0000000000000..7fc4f4498d6df --- /dev/null +++ b/tests/codegen/intrinsics/offset.rs @@ -0,0 +1,34 @@ +// compile-flags: -O -C no-prepopulate-passes +// min-llvm-version: 15.0 (because we're using opaque pointers) + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::offset; + +// CHECK-LABEL: ptr @offset_zst +// CHECK-SAME: (ptr noundef %p, [[SIZE:i[0-9]+]] noundef %d) +#[no_mangle] +pub unsafe fn offset_zst(p: *const (), d: usize) -> *const () { + // CHECK-NOT: getelementptr + // CHECK: ret ptr %p + offset(p, d) +} + +// CHECK-LABEL: ptr @offset_isize +// CHECK-SAME: (ptr noundef %p, [[SIZE]] noundef %d) +#[no_mangle] +pub unsafe fn offset_isize(p: *const u32, d: isize) -> *const u32 { + // CHECK: %[[R:.*]] = getelementptr inbounds i32, ptr %p, [[SIZE]] %d + // CHECK-NEXT: ret ptr %[[R]] + offset(p, d) +} + +// CHECK-LABEL: ptr @offset_usize +// CHECK-SAME: (ptr noundef %p, [[SIZE]] noundef %d) +#[no_mangle] +pub unsafe fn offset_usize(p: *const u64, d: usize) -> *const u64 { + // CHECK: %[[R:.*]] = getelementptr inbounds i64, ptr %p, [[SIZE]] %d + // CHECK-NEXT: ret ptr %[[R]] + offset(p, d) +} diff --git a/tests/mir-opt/lower_intrinsics.ptr_offset.LowerIntrinsics.diff b/tests/mir-opt/lower_intrinsics.ptr_offset.LowerIntrinsics.diff index f342bf30d02ac..e4e228371e606 100644 --- a/tests/mir-opt/lower_intrinsics.ptr_offset.LowerIntrinsics.diff +++ b/tests/mir-opt/lower_intrinsics.ptr_offset.LowerIntrinsics.diff @@ -13,10 +13,10 @@ _3 = _1; // scope 0 at $DIR/lower_intrinsics.rs:+1:30: +1:31 StorageLive(_4); // scope 0 at $DIR/lower_intrinsics.rs:+1:33: +1:34 _4 = _2; // scope 0 at $DIR/lower_intrinsics.rs:+1:33: +1:34 -- _0 = offset::(move _3, move _4) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35 +- _0 = offset::<*const i32, isize>(move _3, move _4) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35 - // mir::Constant - // + span: $DIR/lower_intrinsics.rs:140:5: 140:29 -- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32, isize) -> *const i32 {offset::}, val: Value() } +- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32, isize) -> *const i32 {offset::<*const i32, isize>}, val: Value() } + _0 = Offset(move _3, move _4); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35 + goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35 } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir index 1f15b774cae79..715a1e3fcd479 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.mir @@ -45,16 +45,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { scope 12 (inlined ptr::mut_ptr::::add) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL debug self => _9; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL debug count => _2; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _13: isize; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL scope 13 { - scope 14 (inlined ptr::mut_ptr::::offset) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - debug self => _9; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - debug count => _13; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _14: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _15: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - scope 15 { - } - } } } } @@ -86,16 +77,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL _9 = _8 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _13 = _2 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _14 = Offset(move _15, _13); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _7 = Offset(_9, _2); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir index 8b509290866eb..ea0a44cf3bf79 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir @@ -34,32 +34,23 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> scope 12 (inlined ptr::mut_ptr::::add) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL debug self => _10; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL debug count => _11; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _16: isize; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL scope 13 { - scope 14 (inlined ptr::mut_ptr::::offset) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - debug self => _10; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - debug count => _16; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _17: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - let mut _18: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - scope 15 { - } - } } } - scope 16 (inlined slice_from_raw_parts_mut::) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL - debug data => _9; // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - debug len => _12; // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - let mut _19: *mut (); // in scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - scope 17 (inlined ptr::mut_ptr::::cast::<()>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - debug self => _9; // in scope 17 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + scope 14 (inlined slice_from_raw_parts_mut::) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL + debug data => _9; // in scope 14 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug len => _12; // in scope 14 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + let mut _16: *mut (); // in scope 14 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + scope 15 (inlined ptr::mut_ptr::::cast::<()>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug self => _9; // in scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL } - scope 18 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - debug data_address => _19; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - debug metadata => _12; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - let mut _20: std::ptr::metadata::PtrRepr<[u32]>; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - let mut _21: std::ptr::metadata::PtrComponents<[u32]>; // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - let mut _22: *const (); // in scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - scope 19 { + scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { // at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + debug data_address => _16; // in scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + debug metadata => _12; // in scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _17: std::ptr::metadata::PtrRepr<[u32]>; // in scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _18: std::ptr::metadata::PtrComponents<[u32]>; // in scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + let mut _19: *const (); // in scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + scope 17 { } } } @@ -110,33 +101,24 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> _10 = _4 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL StorageLive(_11); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL _11 = (_2.0: usize); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL - StorageLive(_16); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _16 = _11 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_17); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_18); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _18 = _10 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _17 = Offset(move _18, _16); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_18); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _9 = move _17 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_17); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_16); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _9 = Offset(_10, _11); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL StorageDead(_11); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_10); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageLive(_12); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL _12 = _6; // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL - StorageLive(_19); // scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - _19 = _9 as *mut () (PtrToPtr); // scope 17 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_20); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageLive(_21); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageLive(_22); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - _22 = _19 as *const () (Pointer(MutToConstPointer)); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - _21 = ptr::metadata::PtrComponents::<[u32]> { data_address: move _22, metadata: _12 }; // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageDead(_22); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - _20 = ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _21 }; // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageDead(_21); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - _3 = (_20.1: *mut [u32]); // scope 19 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageDead(_20); // scope 18 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL - StorageDead(_19); // scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + StorageLive(_16); // scope 14 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + _16 = _9 as *mut () (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + StorageLive(_17); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageLive(_18); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageLive(_19); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _19 = _16 as *const () (Pointer(MutToConstPointer)); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _18 = ptr::metadata::PtrComponents::<[u32]> { data_address: move _19, metadata: _12 }; // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_19); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _17 = ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _18 }; // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_18); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + _3 = (_17.1: *mut [u32]); // scope 17 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_17); // scope 16 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL + StorageDead(_16); // scope 14 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL StorageDead(_12); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_6); // scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL diff --git a/tests/ui/const-ptr/forbidden_slices.stderr b/tests/ui/const-ptr/forbidden_slices.stderr index b42361872c475..817cfb0acf90e 100644 --- a/tests/ui/const-ptr/forbidden_slices.stderr +++ b/tests/ui/const-ptr/forbidden_slices.stderr @@ -131,8 +131,6 @@ error[E0080]: could not evaluate static initializer | = note: out-of-bounds pointer arithmetic: allocN has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds | -note: inside `ptr::const_ptr::::offset` - --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `ptr::const_ptr::::add` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `R2` @@ -195,8 +193,6 @@ error[E0080]: could not evaluate static initializer | = note: out-of-bounds pointer arithmetic: allocN has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds | -note: inside `ptr::const_ptr::::offset` - --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `ptr::const_ptr::::add` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `R8`