forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for constant propagation
The results aren't ideal but they represent the current state.
- Loading branch information
1 parent
317daf7
commit b1c4fb2
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
fn main() { | ||
let x: u32 = [0, 1, 2, 3][2]; | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// bb0: { | ||
// ... | ||
// _2 = [const 0u32, const 1u32, const 2u32, const 3u32]; | ||
// ... | ||
// _3 = const 2usize; | ||
// _4 = const 4usize; | ||
// _5 = Lt(_3, _4); | ||
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; | ||
// } | ||
// bb1: { | ||
// _1 = _2[_3]; | ||
// ... | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// bb0: { | ||
// ... | ||
// _5 = const true; | ||
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; | ||
// } | ||
// bb1: { | ||
// _1 = _2[_3]; | ||
// ... | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.after.mir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// compile-flags: -C overflow-checks=on | ||
|
||
fn main() { | ||
let x: u32 = 1 + 1; | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// bb0: { | ||
// ... | ||
// _2 = CheckedAdd(const 1u32, const 1u32); | ||
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1; | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// bb0: { | ||
// ... | ||
// _2 = (const 2u32, const false); | ||
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1; | ||
// } | ||
// END rustc.main.ConstProp.after.mir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
fn test() -> &'static [u32] { | ||
&[1, 2] | ||
} | ||
|
||
fn main() { | ||
let x = test()[0]; | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// bb1: { | ||
// ... | ||
// _3 = const 0usize; | ||
// _4 = Len((*_2)); | ||
// _5 = Lt(_3, _4); | ||
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb2; | ||
// } | ||
// bb2: { | ||
// _1 = (*_2)[_3]; | ||
// ... | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// bb0: { | ||
// ... | ||
// _3 = const 0usize; | ||
// _4 = Len((*_2)); | ||
// _5 = Lt(_3, _4); | ||
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb2; | ||
// } | ||
// bb2: { | ||
// _1 = (*_2)[_3]; | ||
// ... | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.after.mir |