Skip to content

Commit 7a52e73

Browse files
committed
Add tests for Stacked Borrows behavior
1 parent 3c0f3b0 commit 7a52e73

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/ref_with_sb.rs:+0:11: +0:11
6+
let mut _1: i32; // in scope 0 at $DIR/ref_with_sb.rs:+1:9: +1:14
7+
let _2: (); // in scope 0 at $DIR/ref_with_sb.rs:+2:5: +2:15
8+
let mut _3: &i32; // in scope 0 at $DIR/ref_with_sb.rs:+2:12: +2:14
9+
let _4: &i32; // in scope 0 at $DIR/ref_with_sb.rs:+2:12: +2:14
10+
scope 1 {
11+
debug a => _1; // in scope 1 at $DIR/ref_with_sb.rs:+1:9: +1:14
12+
let _5: i32; // in scope 1 at $DIR/ref_with_sb.rs:+6:9: +6:10
13+
scope 2 {
14+
debug b => _5; // in scope 2 at $DIR/ref_with_sb.rs:+6:9: +6:10
15+
}
16+
}
17+
18+
bb0: {
19+
StorageLive(_1); // scope 0 at $DIR/ref_with_sb.rs:+1:9: +1:14
20+
_1 = const 0_i32; // scope 0 at $DIR/ref_with_sb.rs:+1:17: +1:18
21+
StorageLive(_2); // scope 1 at $DIR/ref_with_sb.rs:+2:5: +2:15
22+
StorageLive(_3); // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
23+
StorageLive(_4); // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
24+
_4 = &_1; // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
25+
_3 = &(*_4); // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
26+
_2 = escape::<i32>(move _3) -> bb1; // scope 1 at $DIR/ref_with_sb.rs:+2:5: +2:15
27+
// mir::Constant
28+
// + span: $DIR/ref_with_sb.rs:10:5: 10:11
29+
// + literal: Const { ty: for<'a> fn(&'a i32) {escape::<i32>}, val: Value(<ZST>) }
30+
}
31+
32+
bb1: {
33+
StorageDead(_3); // scope 1 at $DIR/ref_with_sb.rs:+2:14: +2:15
34+
StorageDead(_4); // scope 1 at $DIR/ref_with_sb.rs:+2:15: +2:16
35+
StorageDead(_2); // scope 1 at $DIR/ref_with_sb.rs:+2:15: +2:16
36+
_1 = const 1_i32; // scope 1 at $DIR/ref_with_sb.rs:+3:5: +3:10
37+
StorageLive(_5); // scope 1 at $DIR/ref_with_sb.rs:+6:9: +6:10
38+
- _5 = _1; // scope 1 at $DIR/ref_with_sb.rs:+6:13: +6:14
39+
+ _5 = const 1_i32; // scope 1 at $DIR/ref_with_sb.rs:+6:13: +6:14
40+
_0 = const (); // scope 0 at $DIR/ref_with_sb.rs:+0:11: +7:2
41+
StorageDead(_5); // scope 1 at $DIR/ref_with_sb.rs:+7:1: +7:2
42+
StorageDead(_1); // scope 0 at $DIR/ref_with_sb.rs:+7:1: +7:2
43+
return; // scope 0 at $DIR/ref_with_sb.rs:+7:2: +7:2
44+
}
45+
}
46+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// unit-test: DataflowConstProp
2+
// compile-flags: -Zunsound-mir-opts
3+
4+
#[inline(never)]
5+
fn escape<T>(x: &T) {}
6+
7+
// EMIT_MIR ref_with_sb.main.DataflowConstProp.diff
8+
fn main() {
9+
let mut a = 0;
10+
escape(&a);
11+
a = 1;
12+
// With `-Zunsound-mir-opt`, this should be propagated
13+
// (because we assume Stacked Borrows).
14+
let b = a;
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/ref_without_sb.rs:+0:11: +0:11
6+
let mut _1: i32; // in scope 0 at $DIR/ref_without_sb.rs:+1:9: +1:14
7+
let _2: (); // in scope 0 at $DIR/ref_without_sb.rs:+2:5: +2:15
8+
let mut _3: &i32; // in scope 0 at $DIR/ref_without_sb.rs:+2:12: +2:14
9+
let _4: &i32; // in scope 0 at $DIR/ref_without_sb.rs:+2:12: +2:14
10+
scope 1 {
11+
debug a => _1; // in scope 1 at $DIR/ref_without_sb.rs:+1:9: +1:14
12+
let _5: i32; // in scope 1 at $DIR/ref_without_sb.rs:+6:9: +6:10
13+
scope 2 {
14+
debug b => _5; // in scope 2 at $DIR/ref_without_sb.rs:+6:9: +6:10
15+
}
16+
}
17+
18+
bb0: {
19+
StorageLive(_1); // scope 0 at $DIR/ref_without_sb.rs:+1:9: +1:14
20+
_1 = const 0_i32; // scope 0 at $DIR/ref_without_sb.rs:+1:17: +1:18
21+
StorageLive(_2); // scope 1 at $DIR/ref_without_sb.rs:+2:5: +2:15
22+
StorageLive(_3); // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
23+
StorageLive(_4); // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
24+
_4 = &_1; // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
25+
_3 = &(*_4); // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
26+
_2 = escape::<i32>(move _3) -> bb1; // scope 1 at $DIR/ref_without_sb.rs:+2:5: +2:15
27+
// mir::Constant
28+
// + span: $DIR/ref_without_sb.rs:9:5: 9:11
29+
// + literal: Const { ty: for<'a> fn(&'a i32) {escape::<i32>}, val: Value(<ZST>) }
30+
}
31+
32+
bb1: {
33+
StorageDead(_3); // scope 1 at $DIR/ref_without_sb.rs:+2:14: +2:15
34+
StorageDead(_4); // scope 1 at $DIR/ref_without_sb.rs:+2:15: +2:16
35+
StorageDead(_2); // scope 1 at $DIR/ref_without_sb.rs:+2:15: +2:16
36+
_1 = const 1_i32; // scope 1 at $DIR/ref_without_sb.rs:+3:5: +3:10
37+
StorageLive(_5); // scope 1 at $DIR/ref_without_sb.rs:+6:9: +6:10
38+
_5 = _1; // scope 1 at $DIR/ref_without_sb.rs:+6:13: +6:14
39+
_0 = const (); // scope 0 at $DIR/ref_without_sb.rs:+0:11: +7:2
40+
StorageDead(_5); // scope 1 at $DIR/ref_without_sb.rs:+7:1: +7:2
41+
StorageDead(_1); // scope 0 at $DIR/ref_without_sb.rs:+7:1: +7:2
42+
return; // scope 0 at $DIR/ref_without_sb.rs:+7:2: +7:2
43+
}
44+
}
45+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// unit-test: DataflowConstProp
2+
3+
#[inline(never)]
4+
fn escape<T>(x: &T) {}
5+
6+
// EMIT_MIR ref_without_sb.main.DataflowConstProp.diff
7+
fn main() {
8+
let mut a = 0;
9+
escape(&a);
10+
a = 1;
11+
// Without `-Zunsound-mir-opt`, this should not be propagated
12+
// (because we do not assume Stacked Borrows).
13+
let b = a;
14+
}

0 commit comments

Comments
 (0)