Skip to content

Commit

Permalink
Add test where slice is a const.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 7, 2023
1 parent 4ad22b9 commit b7a925a
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
let _6: usize;
let mut _7: usize;
let mut _8: bool;
let mut _9: &[u32; 3];
let mut _10: &[u32];
let _11: usize;
let mut _12: usize;
let mut _13: bool;
let mut _14: &[u32; 3];
scope 1 {
debug local => _1;
let _9: u32;
scope 2 {
debug constant => _9;
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_9 = const _;
_4 = _9;
_14 = const _;
_4 = _14;
_3 = _4;
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
StorageDead(_3);
Expand All @@ -39,8 +50,26 @@
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_9);
StorageLive(_10);
_10 = const _;
StorageLive(_11);
_11 = const 1_usize;
_12 = Len((*_10));
- _13 = Lt(_11, _12);
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
+ _13 = Lt(const 1_usize, _12);
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
}

bb2: {
- _9 = (*_10)[_11];
+ _9 = (*_10)[1 of 2];
StorageDead(_11);
StorageDead(_10);
_0 = const ();
StorageDead(_9);
StorageDead(_1);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
let _6: usize;
let mut _7: usize;
let mut _8: bool;
let mut _9: &[u32; 3];
let mut _10: &[u32];
let _11: usize;
let mut _12: usize;
let mut _13: bool;
let mut _14: &[u32; 3];
scope 1 {
debug local => _1;
let _9: u32;
scope 2 {
debug constant => _9;
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_9 = const _;
_4 = _9;
_14 = const _;
_4 = _14;
_3 = _4;
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
StorageDead(_3);
Expand All @@ -39,8 +50,26 @@
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_9);
StorageLive(_10);
_10 = const _;
StorageLive(_11);
_11 = const 1_usize;
_12 = Len((*_10));
- _13 = Lt(_11, _12);
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
+ _13 = Lt(const 1_usize, _12);
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
}

bb2: {
- _9 = (*_10)[_11];
+ _9 = (*_10)[1 of 2];
StorageDead(_11);
StorageDead(_10);
_0 = const ();
StorageDead(_9);
StorageDead(_1);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
let _6: usize;
let mut _7: usize;
let mut _8: bool;
let mut _9: &[u32; 3];
let mut _10: &[u32];
let _11: usize;
let mut _12: usize;
let mut _13: bool;
let mut _14: &[u32; 3];
scope 1 {
debug local => _1;
let _9: u32;
scope 2 {
debug constant => _9;
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_9 = const _;
_4 = _9;
_14 = const _;
_4 = _14;
_3 = _4;
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
StorageDead(_3);
Expand All @@ -39,8 +50,26 @@
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_9);
StorageLive(_10);
_10 = const _;
StorageLive(_11);
_11 = const 1_usize;
_12 = Len((*_10));
- _13 = Lt(_11, _12);
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
+ _13 = Lt(const 1_usize, _12);
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
}

bb2: {
- _9 = (*_10)[_11];
+ _9 = (*_10)[1 of 2];
StorageDead(_11);
StorageDead(_10);
_0 = const ();
StorageDead(_9);
StorageDead(_1);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
let _6: usize;
let mut _7: usize;
let mut _8: bool;
let mut _9: &[u32; 3];
let mut _10: &[u32];
let _11: usize;
let mut _12: usize;
let mut _13: bool;
let mut _14: &[u32; 3];
scope 1 {
debug local => _1;
let _9: u32;
scope 2 {
debug constant => _9;
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_9 = const _;
_4 = _9;
_14 = const _;
_4 = _14;
_3 = _4;
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
StorageDead(_3);
Expand All @@ -39,8 +50,26 @@
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_9);
StorageLive(_10);
_10 = const _;
StorageLive(_11);
_11 = const 1_usize;
_12 = Len((*_10));
- _13 = Lt(_11, _12);
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
+ _13 = Lt(const 1_usize, _12);
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
}

bb2: {
- _9 = (*_10)[_11];
+ _9 = (*_10)[1 of 2];
StorageDead(_11);
StorageDead(_10);
_0 = const ();
StorageDead(_9);
StorageDead(_1);
return;
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/mir-opt/dataflow-const-prop/slice_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@

// EMIT_MIR slice_len.main.DataflowConstProp.diff
fn main() {
(&[1u32, 2, 3] as &[u32])[1];
let local = (&[1u32, 2, 3] as &[u32])[1];

const SLICE: &[u32] = &[1, 2, 3];
let constant = SLICE[1];
}

0 comments on commit b7a925a

Please sign in to comment.