Skip to content

Commit 8d5f2bd

Browse files
committed
Add test ensuring that we don't propagate large arrays
1 parent 9e21004 commit 8d5f2bd

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// EMIT_MIR_FOR_EACH_BIT_WIDTH
2+
3+
// EMIT_MIR rustc.main.ConstProp.diff
4+
fn main() {
5+
// check that we don't propagate this, because it's too large
6+
let x: u8 = [0_u8; 5000][2];
7+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/large_array_index.rs:4:11: 4:11
6+
let _1: u8; // in scope 0 at $DIR/large_array_index.rs:6:9: 6:10
7+
let mut _2: [u8; 5000]; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:29
8+
let _3: usize; // in scope 0 at $DIR/large_array_index.rs:6:30: 6:31
9+
let mut _4: usize; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:32
10+
let mut _5: bool; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:32
11+
scope 1 {
12+
debug x => _1; // in scope 1 at $DIR/large_array_index.rs:6:9: 6:10
13+
}
14+
15+
bb0: {
16+
StorageLive(_1); // scope 0 at $DIR/large_array_index.rs:6:9: 6:10
17+
StorageLive(_2); // scope 0 at $DIR/large_array_index.rs:6:17: 6:29
18+
_2 = [const 0_u8; 5000]; // scope 0 at $DIR/large_array_index.rs:6:17: 6:29
19+
// ty::Const
20+
// + ty: u8
21+
// + val: Value(Scalar(0x00))
22+
// mir::Constant
23+
// + span: $DIR/large_array_index.rs:6:18: 6:22
24+
// + literal: Const { ty: u8, val: Value(Scalar(0x00)) }
25+
StorageLive(_3); // scope 0 at $DIR/large_array_index.rs:6:30: 6:31
26+
_3 = const 2_usize; // scope 0 at $DIR/large_array_index.rs:6:30: 6:31
27+
// ty::Const
28+
// + ty: usize
29+
// + val: Value(Scalar(0x00000002))
30+
// mir::Constant
31+
// + span: $DIR/large_array_index.rs:6:30: 6:31
32+
// + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
33+
_4 = const 5000_usize; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
34+
// ty::Const
35+
// + ty: usize
36+
// + val: Value(Scalar(0x00001388))
37+
// mir::Constant
38+
// + span: $DIR/large_array_index.rs:6:17: 6:32
39+
// + literal: Const { ty: usize, val: Value(Scalar(0x00001388)) }
40+
- _5 = Lt(_3, _4); // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
41+
- assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
42+
+ _5 = const true; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
43+
+ // ty::Const
44+
+ // + ty: bool
45+
+ // + val: Value(Scalar(0x01))
46+
+ // mir::Constant
47+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
48+
+ // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
49+
+ assert(const true, "index out of bounds: the len is {} but the index is {}", const 5000_usize, const 2_usize) -> bb1; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
50+
+ // ty::Const
51+
+ // + ty: bool
52+
+ // + val: Value(Scalar(0x01))
53+
+ // mir::Constant
54+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
55+
+ // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
56+
+ // ty::Const
57+
+ // + ty: usize
58+
+ // + val: Value(Scalar(0x00001388))
59+
+ // mir::Constant
60+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
61+
+ // + literal: Const { ty: usize, val: Value(Scalar(0x00001388)) }
62+
+ // ty::Const
63+
+ // + ty: usize
64+
+ // + val: Value(Scalar(0x00000002))
65+
+ // mir::Constant
66+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
67+
+ // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
68+
}
69+
70+
bb1: {
71+
_1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
72+
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:6:32: 6:33
73+
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:6:32: 6:33
74+
_0 = const (); // scope 0 at $DIR/large_array_index.rs:4:11: 7:2
75+
// ty::Const
76+
// + ty: ()
77+
// + val: Value(Scalar(<ZST>))
78+
// mir::Constant
79+
// + span: $DIR/large_array_index.rs:4:11: 7:2
80+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
81+
StorageDead(_1); // scope 0 at $DIR/large_array_index.rs:7:1: 7:2
82+
return; // scope 0 at $DIR/large_array_index.rs:7:2: 7:2
83+
}
84+
}
85+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/large_array_index.rs:4:11: 4:11
6+
let _1: u8; // in scope 0 at $DIR/large_array_index.rs:6:9: 6:10
7+
let mut _2: [u8; 5000]; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:29
8+
let _3: usize; // in scope 0 at $DIR/large_array_index.rs:6:30: 6:31
9+
let mut _4: usize; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:32
10+
let mut _5: bool; // in scope 0 at $DIR/large_array_index.rs:6:17: 6:32
11+
scope 1 {
12+
debug x => _1; // in scope 1 at $DIR/large_array_index.rs:6:9: 6:10
13+
}
14+
15+
bb0: {
16+
StorageLive(_1); // scope 0 at $DIR/large_array_index.rs:6:9: 6:10
17+
StorageLive(_2); // scope 0 at $DIR/large_array_index.rs:6:17: 6:29
18+
_2 = [const 0_u8; 5000]; // scope 0 at $DIR/large_array_index.rs:6:17: 6:29
19+
// ty::Const
20+
// + ty: u8
21+
// + val: Value(Scalar(0x00))
22+
// mir::Constant
23+
// + span: $DIR/large_array_index.rs:6:18: 6:22
24+
// + literal: Const { ty: u8, val: Value(Scalar(0x00)) }
25+
StorageLive(_3); // scope 0 at $DIR/large_array_index.rs:6:30: 6:31
26+
_3 = const 2_usize; // scope 0 at $DIR/large_array_index.rs:6:30: 6:31
27+
// ty::Const
28+
// + ty: usize
29+
// + val: Value(Scalar(0x0000000000000002))
30+
// mir::Constant
31+
// + span: $DIR/large_array_index.rs:6:30: 6:31
32+
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
33+
_4 = const 5000_usize; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
34+
// ty::Const
35+
// + ty: usize
36+
// + val: Value(Scalar(0x0000000000001388))
37+
// mir::Constant
38+
// + span: $DIR/large_array_index.rs:6:17: 6:32
39+
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000001388)) }
40+
- _5 = Lt(_3, _4); // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
41+
- assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
42+
+ _5 = const true; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
43+
+ // ty::Const
44+
+ // + ty: bool
45+
+ // + val: Value(Scalar(0x01))
46+
+ // mir::Constant
47+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
48+
+ // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
49+
+ assert(const true, "index out of bounds: the len is {} but the index is {}", const 5000_usize, const 2_usize) -> bb1; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
50+
+ // ty::Const
51+
+ // + ty: bool
52+
+ // + val: Value(Scalar(0x01))
53+
+ // mir::Constant
54+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
55+
+ // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
56+
+ // ty::Const
57+
+ // + ty: usize
58+
+ // + val: Value(Scalar(0x0000000000001388))
59+
+ // mir::Constant
60+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
61+
+ // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000001388)) }
62+
+ // ty::Const
63+
+ // + ty: usize
64+
+ // + val: Value(Scalar(0x0000000000000002))
65+
+ // mir::Constant
66+
+ // + span: $DIR/large_array_index.rs:6:17: 6:32
67+
+ // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
68+
}
69+
70+
bb1: {
71+
_1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:6:17: 6:32
72+
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:6:32: 6:33
73+
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:6:32: 6:33
74+
_0 = const (); // scope 0 at $DIR/large_array_index.rs:4:11: 7:2
75+
// ty::Const
76+
// + ty: ()
77+
// + val: Value(Scalar(<ZST>))
78+
// mir::Constant
79+
// + span: $DIR/large_array_index.rs:4:11: 7:2
80+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
81+
StorageDead(_1); // scope 0 at $DIR/large_array_index.rs:7:1: 7:2
82+
return; // scope 0 at $DIR/large_array_index.rs:7:2: 7:2
83+
}
84+
}
85+

0 commit comments

Comments
 (0)