Skip to content

Commit bdaa90a

Browse files
Add reaching definitions tests
1 parent 65c8fda commit bdaa90a

8 files changed

+161
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// General test of reaching_defs state computed by MIR dataflow.
2+
3+
#![feature(core_intrinsics, rustc_attrs)]
4+
use std::intrinsics::rustc_peek;
5+
6+
#[rustc_mir(rustc_peek_use_def_chain, stop_after_dataflow, borrowck_graphviz_postflow="flow.dot")]
7+
fn foo(test: bool) -> (i32, i32) {
8+
// Splitting declarations and assignment gives us nicer spans
9+
let mut x;
10+
let mut y;
11+
12+
x=0;
13+
y=1;
14+
15+
if test {
16+
x=2;
17+
unsafe { rustc_peek(&x); }
18+
//~^ ERROR rustc_peek: [16: "x=2"]
19+
} else {
20+
x=3;
21+
y=4;
22+
}
23+
24+
unsafe { rustc_peek(&x); }
25+
//~^ ERROR rustc_peek: [16: "x=2", 17: "rustc_peek(&x)", 20: "x=3"]
26+
27+
unsafe { rustc_peek(&y); }
28+
//~^ ERROR rustc_peek: [13: "y=1", 21: "y=4"]
29+
30+
(x, y)
31+
}
32+
33+
fn main() {
34+
foo(true);
35+
foo(false);
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: rustc_peek: [16: "x=2"]
2+
--> $DIR/reaching-defs-1.rs:17:18
3+
|
4+
LL | unsafe { rustc_peek(&x); }
5+
| ^^^^^^^^^^^^^^
6+
7+
error: rustc_peek: [16: "x=2", 17: "rustc_peek(&x)", 20: "x=3"]
8+
--> $DIR/reaching-defs-1.rs:24:14
9+
|
10+
LL | unsafe { rustc_peek(&x); }
11+
| ^^^^^^^^^^^^^^
12+
13+
error: rustc_peek: [13: "y=1", 21: "y=4"]
14+
--> $DIR/reaching-defs-1.rs:27:14
15+
|
16+
LL | unsafe { rustc_peek(&y); }
17+
| ^^^^^^^^^^^^^^
18+
19+
error: stop_after_dataflow ended compilation
20+
21+
error: aborting due to 4 previous errors
22+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(core_intrinsics, rustc_attrs)]
2+
use std::intrinsics::rustc_peek;
3+
4+
#[rustc_mir(rustc_peek_use_def_chain, stop_after_dataflow, borrowck_graphviz_postflow="flow.dot")]
5+
fn main() {
6+
let mut x;
7+
x=0;
8+
9+
while x != 10 {
10+
x+=1;
11+
}
12+
13+
unsafe { rustc_peek(x); }
14+
//~^ ERROR rustc_peek: [7: "x=0", 10: "x+=1"]
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: rustc_peek: [7: "x=0", 10: "x+=1"]
2+
--> $DIR/reaching-defs-2.rs:13:14
3+
|
4+
LL | unsafe { rustc_peek(x); }
5+
| ^^^^^^^^^^^^^
6+
7+
error: stop_after_dataflow ended compilation
8+
9+
error: aborting due to 2 previous errors
10+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(core_intrinsics, rustc_attrs)]
2+
use std::intrinsics::rustc_peek;
3+
4+
#[rustc_mir(rustc_peek_use_def_chain, stop_after_dataflow, borrowck_graphviz_postflow="flow.dot")]
5+
fn foo(test: bool, mut x: i32) -> i32 {
6+
if test {
7+
x=42;
8+
}
9+
10+
unsafe { rustc_peek(&x); }
11+
//~^ ERROR rustc_peek: [5: "mut x", 7: "x=42"]
12+
13+
x
14+
}
15+
16+
fn main() {
17+
foo(true, 32);
18+
foo(false, 56);
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: rustc_peek: [5: "mut x", 7: "x=42"]
2+
--> $DIR/reaching-defs-arg.rs:10:14
3+
|
4+
LL | unsafe { rustc_peek(&x); }
5+
| ^^^^^^^^^^^^^^
6+
7+
error: stop_after_dataflow ended compilation
8+
9+
error: aborting due to 2 previous errors
10+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(core_intrinsics, rustc_attrs)]
2+
use std::intrinsics::rustc_peek;
3+
4+
#[rustc_mir(rustc_peek_use_def_chain, stop_after_dataflow, borrowck_graphviz_postflow="flow.dot")]
5+
fn foo(test: bool) -> (i32, i32) {
6+
let mut x;
7+
let mut y;
8+
let mut p;
9+
10+
x=0;
11+
y=1;
12+
13+
unsafe { rustc_peek(x); }
14+
//~^ ERROR rustc_peek: [10: "x=0"]
15+
16+
if test {
17+
p = &mut x;
18+
} else {
19+
p = &mut y;
20+
}
21+
22+
*p=2;
23+
24+
unsafe { rustc_peek(x); }
25+
//~^ ERROR rustc_peek: [10: "x=0", 22: "*p=2"]
26+
27+
(x, y)
28+
}
29+
30+
fn main() {
31+
foo(true);
32+
foo(false);
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: rustc_peek: [10: "x=0"]
2+
--> $DIR/reaching-defs-indirect-1.rs:13:14
3+
|
4+
LL | unsafe { rustc_peek(x); }
5+
| ^^^^^^^^^^^^^
6+
7+
error: rustc_peek: [10: "x=0", 22: "*p=2"]
8+
--> $DIR/reaching-defs-indirect-1.rs:24:14
9+
|
10+
LL | unsafe { rustc_peek(x); }
11+
| ^^^^^^^^^^^^^
12+
13+
error: stop_after_dataflow ended compilation
14+
15+
error: aborting due to 3 previous errors
16+

0 commit comments

Comments
 (0)