Skip to content

Commit 05ee406

Browse files
committed
Add test.
1 parent c7bf469 commit 05ee406

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
- // MIR for `main` before CopyProp
2+
+ // MIR for `main` after CopyProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/issue_107511.rs:+0:11: +0:11
6+
let mut _1: i32; // in scope 0 at $DIR/issue_107511.rs:+1:9: +1:16
7+
let _3: (); // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6
8+
let mut _4: std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
9+
let mut _5: std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
10+
let mut _6: usize; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24
11+
let mut _7: &[i32]; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24
12+
let mut _8: &[i32; 4]; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24
13+
let mut _10: (); // in scope 0 at $DIR/issue_107511.rs:+0:1: +11:2
14+
let _11: (); // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
15+
let mut _12: std::option::Option<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
16+
let mut _13: &mut std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
17+
let mut _14: &mut std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24
18+
let mut _15: isize; // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6
19+
let mut _16: !; // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6
20+
let mut _18: i32; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20
21+
let _19: usize; // in scope 0 at $DIR/issue_107511.rs:+7:18: +7:19
22+
let mut _20: usize; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20
23+
let mut _21: bool; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20
24+
scope 1 {
25+
debug sum => _1; // in scope 1 at $DIR/issue_107511.rs:+1:9: +1:16
26+
let _2: [i32; 4]; // in scope 1 at $DIR/issue_107511.rs:+2:9: +2:10
27+
scope 2 {
28+
debug a => _2; // in scope 2 at $DIR/issue_107511.rs:+2:9: +2:10
29+
let mut _9: std::ops::Range<usize>; // in scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
30+
scope 3 {
31+
debug iter => _9; // in scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
32+
let _17: usize; // in scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
33+
scope 4 {
34+
debug i => _17; // in scope 4 at $DIR/issue_107511.rs:+6:9: +6:10
35+
}
36+
}
37+
scope 5 {
38+
}
39+
}
40+
}
41+
42+
bb0: {
43+
StorageLive(_1); // scope 0 at $DIR/issue_107511.rs:+1:9: +1:16
44+
_1 = const 0_i32; // scope 0 at $DIR/issue_107511.rs:+1:19: +1:20
45+
StorageLive(_2); // scope 1 at $DIR/issue_107511.rs:+2:9: +2:10
46+
_2 = [const 0_i32, const 10_i32, const 20_i32, const 30_i32]; // scope 1 at $DIR/issue_107511.rs:+2:13: +2:28
47+
- StorageLive(_3); // scope 2 at $DIR/issue_107511.rs:+6:5: +8:6
48+
StorageLive(_4); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
49+
StorageLive(_5); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
50+
StorageLive(_6); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
51+
StorageLive(_7); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
52+
StorageLive(_8); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
53+
_8 = &_2; // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
54+
_7 = move _8 as &[i32] (Pointer(Unsize)); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
55+
StorageDead(_8); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:18
56+
_6 = core::slice::<impl [i32]>::len(move _7) -> bb1; // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24
57+
// mir::Constant
58+
// + span: $DIR/issue_107511.rs:10:19: 10:22
59+
// + literal: Const { ty: for<'a> fn(&'a [i32]) -> usize {core::slice::<impl [i32]>::len}, val: Value(<ZST>) }
60+
}
61+
62+
bb1: {
63+
StorageDead(_7); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24
64+
Deinit(_5); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
65+
(_5.0: usize) = const 0_usize; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
66+
(_5.1: usize) = move _6; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
67+
StorageDead(_6); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24
68+
_4 = <std::ops::Range<usize> as IntoIterator>::into_iter(move _5) -> bb2; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
69+
// mir::Constant
70+
// + span: $DIR/issue_107511.rs:10:14: 10:24
71+
// + literal: Const { ty: fn(std::ops::Range<usize>) -> <std::ops::Range<usize> as IntoIterator>::IntoIter {<std::ops::Range<usize> as IntoIterator>::into_iter}, val: Value(<ZST>) }
72+
}
73+
74+
bb2: {
75+
StorageDead(_5); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24
76+
StorageLive(_9); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
77+
_9 = move _4; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24
78+
goto -> bb3; // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6
79+
}
80+
81+
bb3: {
82+
- StorageLive(_11); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
83+
StorageLive(_12); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
84+
StorageLive(_13); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
85+
StorageLive(_14); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
86+
_14 = &mut _9; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
87+
_13 = &mut (*_14); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
88+
_12 = <std::ops::Range<usize> as Iterator>::next(move _13) -> bb4; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
89+
// mir::Constant
90+
// + span: $DIR/issue_107511.rs:10:14: 10:24
91+
// + literal: Const { ty: for<'a> fn(&'a mut std::ops::Range<usize>) -> Option<<std::ops::Range<usize> as Iterator>::Item> {<std::ops::Range<usize> as Iterator>::next}, val: Value(<ZST>) }
92+
}
93+
94+
bb4: {
95+
StorageDead(_13); // scope 3 at $DIR/issue_107511.rs:+6:23: +6:24
96+
_15 = discriminant(_12); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
97+
switchInt(move _15) -> [0: bb7, 1: bb5, otherwise: bb6]; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
98+
}
99+
100+
bb5: {
101+
StorageLive(_17); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
102+
_17 = ((_12 as Some).0: usize); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
103+
StorageLive(_18); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
104+
- StorageLive(_19); // scope 4 at $DIR/issue_107511.rs:+7:18: +7:19
105+
- _19 = _17; // scope 4 at $DIR/issue_107511.rs:+7:18: +7:19
106+
_20 = Len(_2); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
107+
- _21 = Lt(_19, _20); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
108+
- assert(move _21, "index out of bounds: the length is {} but the index is {}", move _20, _19) -> bb8; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
109+
+ _21 = Lt(_17, _20); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
110+
+ assert(move _21, "index out of bounds: the length is {} but the index is {}", move _20, _17) -> bb8; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
111+
}
112+
113+
bb6: {
114+
unreachable; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24
115+
}
116+
117+
bb7: {
118+
- _3 = const (); // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6
119+
StorageDead(_14); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
120+
StorageDead(_12); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
121+
- StorageDead(_11); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
122+
StorageDead(_9); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6
123+
StorageDead(_4); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6
124+
- StorageDead(_3); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6
125+
_0 = const (); // scope 0 at $DIR/issue_107511.rs:+0:11: +11:2
126+
StorageDead(_2); // scope 1 at $DIR/issue_107511.rs:+11:1: +11:2
127+
StorageDead(_1); // scope 0 at $DIR/issue_107511.rs:+11:1: +11:2
128+
return; // scope 0 at $DIR/issue_107511.rs:+11:2: +11:2
129+
}
130+
131+
bb8: {
132+
- _18 = _2[_19]; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
133+
+ _18 = _2[_17]; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
134+
_1 = Add(_1, move _18); // scope 4 at $DIR/issue_107511.rs:+7:9: +7:20
135+
StorageDead(_18); // scope 4 at $DIR/issue_107511.rs:+7:19: +7:20
136+
- StorageDead(_19); // scope 4 at $DIR/issue_107511.rs:+7:20: +7:21
137+
- _11 = const (); // scope 4 at $DIR/issue_107511.rs:+6:25: +8:6
138+
- StorageDead(_17); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
139+
StorageDead(_14); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
140+
StorageDead(_12); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
141+
- StorageDead(_11); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6
142+
- _10 = const (); // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6
143+
goto -> bb3; // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6
144+
}
145+
}
146+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// unit-test: CopyProp
2+
3+
// EMIT_MIR issue_107511.main.CopyProp.diff
4+
fn main() {
5+
let mut sum = 0;
6+
let a = [0, 10, 20, 30];
7+
8+
// `i` is assigned in a loop. Only removing its `StorageDead` would mean that
9+
// execution sees repeated `StorageLive`. This would be UB.
10+
for i in 0..a.len() {
11+
sum += a[i];
12+
}
13+
14+
let _ = sum;
15+
}

0 commit comments

Comments
 (0)