Skip to content

Commit 95fd4c6

Browse files
committed
Add some tests for constant propagation
The results aren't ideal but they represent the current state.
1 parent 343274b commit 95fd4c6

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
fn main() {
2+
let x: u32 = [0, 1, 2, 3][2];
3+
}
4+
5+
// END RUST SOURCE
6+
// START rustc.main.ConstProp.before.mir
7+
// bb0: {
8+
// ...
9+
// _2 = [const 0u32, const 1u32, const 2u32, const 3u32];
10+
// ...
11+
// _3 = const 2usize;
12+
// _4 = const 4usize;
13+
// _5 = Lt(_3, _4);
14+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
15+
// }
16+
// bb1: {
17+
// _1 = _2[_3];
18+
// ...
19+
// return;
20+
// }
21+
// END rustc.main.ConstProp.before.mir
22+
// START rustc.main.ConstProp.after.mir
23+
// bb0: {
24+
// ...
25+
// _5 = const true;
26+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
27+
// }
28+
// bb1: {
29+
// _1 = _2[_3];
30+
// ...
31+
// return;
32+
// }
33+
// END rustc.main.ConstProp.after.mir
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags: -C overflow-checks=on
2+
3+
fn main() {
4+
let x: u32 = 1 + 1;
5+
}
6+
7+
// END RUST SOURCE
8+
// START rustc.main.ConstProp.before.mir
9+
// bb0: {
10+
// ...
11+
// _2 = CheckedAdd(const 1u32, const 1u32);
12+
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
13+
// }
14+
// END rustc.main.ConstProp.before.mir
15+
// START rustc.main.ConstProp.after.mir
16+
// bb0: {
17+
// ...
18+
// _2 = (const 2u32, const false);
19+
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
20+
// }
21+
// END rustc.main.ConstProp.after.mir
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
fn test() -> &'static [u32] {
2+
&[1, 2]
3+
}
4+
5+
fn main() {
6+
let x = test()[0];
7+
}
8+
9+
// END RUST SOURCE
10+
// START rustc.main.ConstProp.before.mir
11+
// bb1: {
12+
// ...
13+
// _3 = const 0usize;
14+
// _4 = Len((*_2));
15+
// _5 = Lt(_3, _4);
16+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb2;
17+
// }
18+
// bb2: {
19+
// _1 = (*_2)[_3];
20+
// ...
21+
// return;
22+
// }
23+
// END rustc.main.ConstProp.before.mir
24+
// START rustc.main.ConstProp.after.mir
25+
// bb0: {
26+
// ...
27+
// _3 = const 0usize;
28+
// _4 = Len((*_2));
29+
// _5 = Lt(_3, _4);
30+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb2;
31+
// }
32+
// bb2: {
33+
// _1 = (*_2)[_3];
34+
// ...
35+
// return;
36+
// }
37+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)