Skip to content

Commit b7a925a

Browse files
committed
Add test where slice is a const.
1 parent 4ad22b9 commit b7a925a

5 files changed

+136
-17
lines changed

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff

+33-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111
let _6: usize;
1212
let mut _7: usize;
1313
let mut _8: bool;
14-
let mut _9: &[u32; 3];
14+
let mut _10: &[u32];
15+
let _11: usize;
16+
let mut _12: usize;
17+
let mut _13: bool;
18+
let mut _14: &[u32; 3];
19+
scope 1 {
20+
debug local => _1;
21+
let _9: u32;
22+
scope 2 {
23+
debug constant => _9;
24+
}
25+
}
1526

1627
bb0: {
1728
StorageLive(_1);
1829
StorageLive(_2);
1930
StorageLive(_3);
2031
StorageLive(_4);
21-
_9 = const _;
22-
_4 = _9;
32+
_14 = const _;
33+
_4 = _14;
2334
_3 = _4;
2435
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
2536
StorageDead(_3);
@@ -39,8 +50,26 @@
3950
StorageDead(_6);
4051
StorageDead(_4);
4152
StorageDead(_2);
42-
StorageDead(_1);
53+
StorageLive(_9);
54+
StorageLive(_10);
55+
_10 = const _;
56+
StorageLive(_11);
57+
_11 = const 1_usize;
58+
_12 = Len((*_10));
59+
- _13 = Lt(_11, _12);
60+
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
61+
+ _13 = Lt(const 1_usize, _12);
62+
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
63+
}
64+
65+
bb2: {
66+
- _9 = (*_10)[_11];
67+
+ _9 = (*_10)[1 of 2];
68+
StorageDead(_11);
69+
StorageDead(_10);
4370
_0 = const ();
71+
StorageDead(_9);
72+
StorageDead(_1);
4473
return;
4574
}
4675
}

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff

+33-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111
let _6: usize;
1212
let mut _7: usize;
1313
let mut _8: bool;
14-
let mut _9: &[u32; 3];
14+
let mut _10: &[u32];
15+
let _11: usize;
16+
let mut _12: usize;
17+
let mut _13: bool;
18+
let mut _14: &[u32; 3];
19+
scope 1 {
20+
debug local => _1;
21+
let _9: u32;
22+
scope 2 {
23+
debug constant => _9;
24+
}
25+
}
1526

1627
bb0: {
1728
StorageLive(_1);
1829
StorageLive(_2);
1930
StorageLive(_3);
2031
StorageLive(_4);
21-
_9 = const _;
22-
_4 = _9;
32+
_14 = const _;
33+
_4 = _14;
2334
_3 = _4;
2435
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
2536
StorageDead(_3);
@@ -39,8 +50,26 @@
3950
StorageDead(_6);
4051
StorageDead(_4);
4152
StorageDead(_2);
42-
StorageDead(_1);
53+
StorageLive(_9);
54+
StorageLive(_10);
55+
_10 = const _;
56+
StorageLive(_11);
57+
_11 = const 1_usize;
58+
_12 = Len((*_10));
59+
- _13 = Lt(_11, _12);
60+
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
61+
+ _13 = Lt(const 1_usize, _12);
62+
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
63+
}
64+
65+
bb2: {
66+
- _9 = (*_10)[_11];
67+
+ _9 = (*_10)[1 of 2];
68+
StorageDead(_11);
69+
StorageDead(_10);
4370
_0 = const ();
71+
StorageDead(_9);
72+
StorageDead(_1);
4473
return;
4574
}
4675
}

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff

+33-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111
let _6: usize;
1212
let mut _7: usize;
1313
let mut _8: bool;
14-
let mut _9: &[u32; 3];
14+
let mut _10: &[u32];
15+
let _11: usize;
16+
let mut _12: usize;
17+
let mut _13: bool;
18+
let mut _14: &[u32; 3];
19+
scope 1 {
20+
debug local => _1;
21+
let _9: u32;
22+
scope 2 {
23+
debug constant => _9;
24+
}
25+
}
1526

1627
bb0: {
1728
StorageLive(_1);
1829
StorageLive(_2);
1930
StorageLive(_3);
2031
StorageLive(_4);
21-
_9 = const _;
22-
_4 = _9;
32+
_14 = const _;
33+
_4 = _14;
2334
_3 = _4;
2435
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
2536
StorageDead(_3);
@@ -39,8 +50,26 @@
3950
StorageDead(_6);
4051
StorageDead(_4);
4152
StorageDead(_2);
42-
StorageDead(_1);
53+
StorageLive(_9);
54+
StorageLive(_10);
55+
_10 = const _;
56+
StorageLive(_11);
57+
_11 = const 1_usize;
58+
_12 = Len((*_10));
59+
- _13 = Lt(_11, _12);
60+
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
61+
+ _13 = Lt(const 1_usize, _12);
62+
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
63+
}
64+
65+
bb2: {
66+
- _9 = (*_10)[_11];
67+
+ _9 = (*_10)[1 of 2];
68+
StorageDead(_11);
69+
StorageDead(_10);
4370
_0 = const ();
71+
StorageDead(_9);
72+
StorageDead(_1);
4473
return;
4574
}
4675
}

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff

+33-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111
let _6: usize;
1212
let mut _7: usize;
1313
let mut _8: bool;
14-
let mut _9: &[u32; 3];
14+
let mut _10: &[u32];
15+
let _11: usize;
16+
let mut _12: usize;
17+
let mut _13: bool;
18+
let mut _14: &[u32; 3];
19+
scope 1 {
20+
debug local => _1;
21+
let _9: u32;
22+
scope 2 {
23+
debug constant => _9;
24+
}
25+
}
1526

1627
bb0: {
1728
StorageLive(_1);
1829
StorageLive(_2);
1930
StorageLive(_3);
2031
StorageLive(_4);
21-
_9 = const _;
22-
_4 = _9;
32+
_14 = const _;
33+
_4 = _14;
2334
_3 = _4;
2435
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
2536
StorageDead(_3);
@@ -39,8 +50,26 @@
3950
StorageDead(_6);
4051
StorageDead(_4);
4152
StorageDead(_2);
42-
StorageDead(_1);
53+
StorageLive(_9);
54+
StorageLive(_10);
55+
_10 = const _;
56+
StorageLive(_11);
57+
_11 = const 1_usize;
58+
_12 = Len((*_10));
59+
- _13 = Lt(_11, _12);
60+
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
61+
+ _13 = Lt(const 1_usize, _12);
62+
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
63+
}
64+
65+
bb2: {
66+
- _9 = (*_10)[_11];
67+
+ _9 = (*_10)[1 of 2];
68+
StorageDead(_11);
69+
StorageDead(_10);
4370
_0 = const ();
71+
StorageDead(_9);
72+
StorageDead(_1);
4473
return;
4574
}
4675
}

tests/mir-opt/dataflow-const-prop/slice_len.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55

66
// EMIT_MIR slice_len.main.DataflowConstProp.diff
77
fn main() {
8-
(&[1u32, 2, 3] as &[u32])[1];
8+
let local = (&[1u32, 2, 3] as &[u32])[1];
9+
10+
const SLICE: &[u32] = &[1, 2, 3];
11+
let constant = SLICE[1];
912
}

0 commit comments

Comments
 (0)