1- //@ compile-flags: -C opt-level=0
1+ //@ compile-flags: -Zmir-opt-level=0 - C opt-level=0
22
33// EMIT_MIR index_array_and_slice.index_array.built.after.mir
44fn index_array ( array : & [ i32 ; 7 ] , index : usize ) -> & i32 {
55 // CHECK: bb0:
6- // CHECK: [[LT:_.+]] = Lt(copy _2, const 7_usize);
7- // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", const 7_usize, copy _2) -> [success: bb1, unwind
6+ // CHECK: _3 = copy _2;
7+ // CHECK: [[LT:_.+]] = Lt(copy _3, const 7_usize);
8+ // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", const 7_usize, copy _3) -> [success: bb1, unwind
89
910 // CHECK: bb1:
10- // CHECK: _0 = &(*_1)[_2];
11+ // CHECK: _5 = &(*_1)[_3];
12+ // CHECK: _0 = &(*_5);
1113 & array[ index]
1214}
1315
1416// EMIT_MIR index_array_and_slice.index_const_generic_array.built.after.mir
1517fn index_const_generic_array < const N : usize > ( array : & [ i32 ; N ] , index : usize ) -> & i32 {
1618 // CHECK: bb0:
17- // CHECK: [[LT:_.+]] = Lt(copy _2, const N);
18- // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", const N, copy _2) -> [success: bb1, unwind
19+ // CHECK: _3 = copy _2;
20+ // CHECK: [[LT:_.+]] = Lt(copy _3, const N);
21+ // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", const N, copy _3) -> [success: bb1, unwind
1922
2023 // CHECK: bb1:
21- // CHECK: _0 = &(*_1)[_2];
24+ // CHECK: _5 = &(*_1)[_3];
25+ // CHECK: _0 = &(*_5);
2226 & array[ index]
2327}
2428
2529// EMIT_MIR index_array_and_slice.index_slice.built.after.mir
2630fn index_slice ( slice : & [ i32 ] , index : usize ) -> & i32 {
2731 // CHECK: bb0:
32+ // CHECK: _3 = copy _2;
2833 // CHECK: [[LEN:_.+]] = PtrMetadata(copy _1);
29- // CHECK: [[LT:_.+]] = Lt(copy _2 , copy [[LEN]]);
30- // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _2 ) -> [success: bb1,
34+ // CHECK: [[LT:_.+]] = Lt(copy _3 , copy [[LEN]]);
35+ // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _3 ) -> [success: bb1,
3136
3237 // CHECK: bb1:
33- // CHECK: _0 = &(*_1)[_2];
38+ // CHECK: _6 = &(*_1)[_3];
39+ // CHECK: _0 = &(*_6);
3440 & slice[ index]
3541}
3642
@@ -40,12 +46,15 @@ fn index_mut_slice(slice: &mut [i32], index: usize) -> &i32 {
4046 // This cannot `copy _1` in the *built* MIR, only in the *runtime* MIR.
4147
4248 // CHECK: bb0:
43- // CHECK: [[LEN:_.+]] = PtrMetadata(copy _1);
44- // CHECK: [[LT:_.+]] = Lt(copy _2, copy [[LEN]]);
45- // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _2) -> [success: bb1,
49+ // CHECK: _3 = copy _2;
50+ // CHECK: _4 = &raw const (fake) (*_1);
51+ // CHECK: [[LEN:_.+]] = PtrMetadata(move _4);
52+ // CHECK: [[LT:_.+]] = Lt(copy _3, copy [[LEN]]);
53+ // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _3) -> [success: bb1,
4654
4755 // CHECK: bb1:
48- // CHECK: _0 = &(*_1)[_2];
56+ // CHECK: _7 = &(*_1)[_3];
57+ // CHECK: _0 = &(*_7);
4958 & slice[ index]
5059}
5160
@@ -54,13 +63,15 @@ struct WithSliceTail(f64, [i32]);
5463// EMIT_MIR index_array_and_slice.index_custom.built.after.mir
5564fn index_custom ( custom : & WithSliceTail , index : usize ) -> & i32 {
5665 // CHECK: bb0:
66+ // CHECK: _3 = copy _2;
5767 // CHECK: [[PTR:_.+]] = &raw const (fake) ((*_1).1: [i32]);
58- // CHECK: [[LEN:_.+]] = PtrMetadata(copy [[PTR]]);
59- // CHECK: [[LT:_.+]] = Lt(copy _2 , copy [[LEN]]);
60- // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _2 ) -> [success: bb1,
68+ // CHECK: [[LEN:_.+]] = PtrMetadata(move [[PTR]]);
69+ // CHECK: [[LT:_.+]] = Lt(copy _3 , copy [[LEN]]);
70+ // CHECK: assert(move [[LT]], "index out of bounds{{.+}}", move [[LEN]], copy _3 ) -> [success: bb1,
6171
6272 // CHECK: bb1:
63- // CHECK: _0 = &((*_1).1: [i32])[_2];
73+ // CHECK: _7 = &((*_1).1: [i32])[_3];
74+ // CHECK: _0 = &(*_7);
6475 & custom. 1 [ index]
6576}
6677
0 commit comments