Skip to content

Commit 8bcfc0e

Browse files
committed
Add some MIR pre-codegen tests for slice indexing
1 parent 1c42cb4 commit 8bcfc0e

5 files changed

+348
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
2+
// only-64bit
3+
// ignore-debug
4+
5+
#![crate_type = "lib"]
6+
7+
use std::ops::Range;
8+
9+
// EMIT_MIR slice_index.slice_index_usize.PreCodegen.after.mir
10+
pub fn slice_index_usize(slice: &[u32], index: usize) -> u32 {
11+
slice[index]
12+
}
13+
14+
// EMIT_MIR slice_index.slice_get_mut_usize.PreCodegen.after.mir
15+
pub fn slice_get_mut_usize(slice: &mut [u32], index: usize) -> Option<&mut u32> {
16+
slice.get_mut(index)
17+
}
18+
19+
// EMIT_MIR slice_index.slice_index_range.PreCodegen.after.mir
20+
pub fn slice_index_range(slice: &[u32], index: Range<usize>) -> &[u32] {
21+
&slice[index]
22+
}
23+
24+
// EMIT_MIR slice_index.slice_get_unchecked_mut_range.PreCodegen.after.mir
25+
pub unsafe fn slice_get_unchecked_mut_range(slice: &mut [u32], index: Range<usize>) -> &mut [u32] {
26+
slice.get_unchecked_mut(index)
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// MIR for `slice_get_mut_usize` after PreCodegen
2+
3+
fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
4+
debug slice => _1; // in scope 0 at $DIR/slice_index.rs:+0:28: +0:33
5+
debug index => _2; // in scope 0 at $DIR/slice_index.rs:+0:47: +0:52
6+
let mut _0: std::option::Option<&mut u32>; // return place in scope 0 at $DIR/slice_index.rs:+0:64: +0:80
7+
scope 1 (inlined core::slice::<impl [u32]>::get_mut::<usize>) { // at $DIR/slice_index.rs:16:11: 16:25
8+
debug self => _1; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL
9+
debug index => _2; // in scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL
10+
scope 2 (inlined <usize as SliceIndex<[u32]>>::get_mut) { // at $SRC_DIR/core/src/slice/mod.rs:LL:COL
11+
debug self => _2; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
12+
debug slice => _1; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
13+
let mut _3: bool; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
14+
let mut _4: usize; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
15+
let mut _5: &[u32]; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
16+
let mut _6: &mut u32; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
17+
let mut _7: *mut u32; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
18+
let mut _8: *mut [u32]; // in scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
19+
scope 3 {
20+
scope 4 (inlined <usize as SliceIndex<[u32]>>::get_unchecked_mut) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL
21+
debug self => _2; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL
22+
debug slice => _8; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL
23+
let mut _9: *mut u32; // in scope 4 at $SRC_DIR/core/src/slice/index.rs:LL:COL
24+
let mut _10: usize; // in scope 4 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
25+
let mut _11: *mut [u32]; // in scope 4 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
26+
scope 5 {
27+
debug this => _2; // in scope 5 at $SRC_DIR/core/src/slice/index.rs:LL:COL
28+
scope 6 {
29+
scope 7 (inlined <usize as SliceIndex<[T]>>::get_unchecked_mut::runtime::<u32>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
30+
debug this => _10; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
31+
debug slice => _11; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
32+
scope 8 (inlined ptr::mut_ptr::<impl *mut [u32]>::len) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL
33+
debug self => _11; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
34+
let mut _12: *const [u32]; // in scope 8 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
35+
scope 9 (inlined std::ptr::metadata::<[u32]>) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
36+
debug ptr => _12; // in scope 9 at $SRC_DIR/core/src/ptr/metadata.rs:LL:COL
37+
scope 10 {
38+
}
39+
}
40+
}
41+
}
42+
scope 11 (inlined ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL
43+
debug self => _8; // in scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
44+
}
45+
scope 12 (inlined ptr::mut_ptr::<impl *mut u32>::add) { // at $SRC_DIR/core/src/slice/index.rs:LL:COL
46+
debug self => _9; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
47+
debug count => _2; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
48+
let mut _13: isize; // in scope 12 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
49+
scope 13 {
50+
scope 14 (inlined ptr::mut_ptr::<impl *mut u32>::offset) { // at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
51+
debug self => _9; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
52+
debug count => _13; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
53+
let mut _14: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
54+
let mut _15: *const u32; // in scope 14 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
55+
scope 15 {
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
67+
bb0: {
68+
StorageLive(_6); // scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL
69+
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
70+
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
71+
StorageLive(_5); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
72+
_5 = &(*_1); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
73+
_4 = Len((*_5)); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
74+
StorageDead(_5); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
75+
_3 = Lt(_2, move _4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
76+
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
77+
switchInt(move _3) -> [0: bb2, otherwise: bb1]; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
78+
}
79+
80+
bb1: {
81+
StorageLive(_7); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
82+
StorageLive(_8); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
83+
_8 = &raw mut (*_1); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
84+
StorageLive(_10); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
85+
StorageLive(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
86+
StorageLive(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
87+
StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
88+
_9 = _8 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
89+
StorageLive(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
90+
_13 = _2 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
91+
StorageLive(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
92+
StorageLive(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
93+
_15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
94+
_14 = Offset(move _15, _13); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
95+
StorageDead(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
96+
_7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
97+
StorageDead(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
98+
StorageDead(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
99+
StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
100+
StorageDead(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
101+
StorageDead(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
102+
StorageDead(_10); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
103+
StorageDead(_8); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
104+
_6 = &mut (*_7); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
105+
_0 = Option::<&mut u32>::Some(_6); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
106+
StorageDead(_7); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
107+
goto -> bb3; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
108+
}
109+
110+
bb2: {
111+
_0 = const Option::<&mut u32>::None; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
112+
// mir::Constant
113+
// + span: no-location
114+
// + literal: Const { ty: Option<&mut u32>, val: Value(Scalar(0x0000000000000000)) }
115+
goto -> bb3; // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
116+
}
117+
118+
bb3: {
119+
StorageDead(_3); // scope 2 at $SRC_DIR/core/src/slice/index.rs:LL:COL
120+
StorageDead(_6); // scope 1 at $SRC_DIR/core/src/slice/mod.rs:LL:COL
121+
return; // scope 0 at $DIR/slice_index.rs:+2:2: +2:2
122+
}
123+
}

0 commit comments

Comments
 (0)