Skip to content

Commit 33e5d85

Browse files
committed
Add FileCheck for enum.rs
1 parent e05c779 commit 33e5d85

8 files changed

+86
-34
lines changed

tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let _6: u8;
1515
let _8: u8;
1616
scope 2 {
17-
debug x => _6;
17+
debug x2 => _6;
1818
let _9: u8;
1919
scope 4 {
2020
debug y => _9;

tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let _6: u8;
1515
let _8: u8;
1616
scope 2 {
17-
debug x => _6;
17+
debug x2 => _6;
1818
let _9: u8;
1919
scope 4 {
2020
debug y => _9;

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

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_BIT_WIDTH
43

@@ -13,34 +12,75 @@ enum E {
1312
}
1413

1514
// EMIT_MIR enum.simple.DataflowConstProp.diff
15+
16+
// CHECK-LABEL: fn simple(
1617
fn simple() {
18+
// CHECK: debug e => [[e:_.*]];
19+
// CHECK: debug x => [[x:_.*]];
20+
// CHECK: [[e]] = const E::V1(0_i32);
1721
let e = E::V1(0);
18-
let x = match e { E::V1(x) => x, E::V2(x) => x };
22+
23+
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb:[0-9]+]], 1: bb1, otherwise: bb2];
24+
// CHECK: bb[[target_bb]]: {
25+
// CHECK: [[x]] = const 0_i32;
26+
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
1927
}
2028

2129
// EMIT_MIR enum.constant.DataflowConstProp.diff
30+
31+
// CHECK-LABEL: fn constant(
2232
fn constant() {
33+
// CHECK: debug e => [[e:_.*]];
34+
// CHECK: debug x => [[x:_.*]];
2335
const C: E = E::V1(0);
36+
37+
// CHECK: [[e]] = const _;
2438
let e = C;
25-
let x = match e { E::V1(x) => x, E::V2(x) => x };
39+
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb:[0-9]+]], 1: bb1, otherwise: bb2];
40+
// CHECK: bb[[target_bb]]: {
41+
// CHECK: [[x]] = const 0_i32;
42+
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
2643
}
2744

2845
// EMIT_MIR enum.statics.DataflowConstProp.diff
46+
47+
// CHECK-LABEL: fn statics(
2948
fn statics() {
49+
// CHECK: debug e1 => [[e1:_.*]];
50+
// CHECK: debug x1 => [[x1:_.*]];
51+
// CHECK: debug e2 => [[e2:_.*]];
52+
// CHECK: debug x2 => [[x2:_.*]];
53+
3054
static C: E = E::V1(0);
31-
let e = C;
32-
let x = match e { E::V1(x) => x, E::V2(x) => x };
55+
56+
// CHECK: [[e1]] = const E::V1(0_i32);
57+
let e1 = C;
58+
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb1:[0-9]+]], 1: bb1, otherwise: bb2];
59+
// CHECK: bb[[target_bb]]: {
60+
// CHECK: [[x1]] = const 0_i32;
61+
let x1 = match e1 { E::V1(x11) => x11, E::V2(x12) => x12 };
3362

3463
static RC: &E = &E::V2(4);
35-
let e = RC;
36-
let x = match e { E::V1(x) => x, E::V2(x) => x };
64+
65+
// CHECK: [[t:_.*]] = const {alloc2: &&E};
66+
// CHECK: [[e2]] = (*[[t]]);
67+
let e2 = RC;
68+
// CHECK: switchInt(move _{{[0-9]+}}) -> [0: bb{{[0-9]+}}, 1: bb{{[0-9]+}}, otherwise: bb{{[0-9]+}}];
69+
// FIXME: add checks for x2. Currently, their MIRs are not symmetric in the two
70+
// switch branches.
71+
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
72+
// get by printing MIR directly. It is better to check if there are any bugs in the
73+
// MIR passes around this stage.
74+
let x2 = match e2 { E::V1(x21) => x21, E::V2(x22) => x22 };
3775
}
3876

3977
#[rustc_layout_scalar_valid_range_start(1)]
4078
#[rustc_nonnull_optimization_guaranteed]
4179
struct NonZeroUsize(usize);
4280

4381
// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff
82+
83+
// CHECK-LABEL: fn mutate_discriminant(
4484
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
4585
fn mutate_discriminant() -> u8 {
4686
mir!(
@@ -50,7 +90,11 @@ fn mutate_discriminant() -> u8 {
5090
// This assignment overwrites the niche in which the discriminant is stored.
5191
place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize;
5292
// So we cannot know the value of this discriminant.
93+
94+
// CHECK: [[a:_.*]] = discriminant(_{{[0-9]*}});
5395
let a = Discriminant(x);
96+
97+
// CHECK: switchInt([[a]]) -> [0: bb{{[0-9]+}}, otherwise: bb{{[0-9]+}}];
5498
match a {
5599
0 => bb1,
56100
_ => bad,
@@ -68,18 +112,26 @@ fn mutate_discriminant() -> u8 {
68112
}
69113

70114
// EMIT_MIR enum.multiple.DataflowConstProp.diff
115+
// CHECK-LABEL: fn multiple(
71116
fn multiple(x: bool, i: u8) {
117+
// CHECK: debug x => [[x:_.*]];
118+
// CHECK: debug e => [[e:_.*]];
119+
// CHECK: debug x2 => [[x2:_.*]];
72120
let e = if x {
121+
// CHECK: [[e]] = Option::<u8>::Some(move _{{[0-9]+}});
73122
Some(i)
74123
} else {
124+
// CHECK: [[e]] = Option::<u8>::None;
75125
None
76126
};
77127
// The dataflow state must have:
78128
// discriminant(e) => Top
79129
// (e as Some).0 => Top
80-
let x = match e { Some(i) => i, None => 0 };
81-
// Therefore, `x` should be `Top` here, and no replacement shall happen.
82-
let y = x;
130+
// CHECK: [[x2]] = const 0_u8;
131+
// CHECK: [[x2]] = _{{[0-9]+}}
132+
let x2 = match e { Some(i) => i, None => 0 };
133+
// Therefore, `x2` should be `Top` here, and no replacement shall happen.
134+
let y = x2;
83135
}
84136

85137
fn main() {

tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
let mut _8: &&E;
1010
let mut _10: isize;
1111
scope 1 {
12-
debug e => _1;
12+
debug e1 => _1;
1313
let _3: i32;
1414
let _5: i32;
1515
let _6: i32;
1616
scope 2 {
17-
debug x => _3;
17+
debug x1 => _3;
1818
let _7: &E;
1919
scope 5 {
20-
debug e => _7;
20+
debug e2 => _7;
2121
let _9: &i32;
2222
let _11: &i32;
2323
let _12: &i32;
2424
scope 6 {
25-
debug x => _9;
25+
debug x2 => _9;
2626
}
2727
scope 7 {
28-
debug x => _11;
28+
debug x21 => _11;
2929
}
3030
scope 8 {
31-
debug x => _12;
31+
debug x22 => _12;
3232
}
3333
}
3434
}
3535
scope 3 {
36-
debug x => _5;
36+
debug x11 => _5;
3737
}
3838
scope 4 {
39-
debug x => _6;
39+
debug x12 => _6;
4040
}
4141
}
4242

tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
let mut _8: &&E;
1010
let mut _10: isize;
1111
scope 1 {
12-
debug e => _1;
12+
debug e1 => _1;
1313
let _3: i32;
1414
let _5: i32;
1515
let _6: i32;
1616
scope 2 {
17-
debug x => _3;
17+
debug x1 => _3;
1818
let _7: &E;
1919
scope 5 {
20-
debug e => _7;
20+
debug e2 => _7;
2121
let _9: &i32;
2222
let _11: &i32;
2323
let _12: &i32;
2424
scope 6 {
25-
debug x => _9;
25+
debug x2 => _9;
2626
}
2727
scope 7 {
28-
debug x => _11;
28+
debug x21 => _11;
2929
}
3030
scope 8 {
31-
debug x => _12;
31+
debug x22 => _12;
3232
}
3333
}
3434
}
3535
scope 3 {
36-
debug x => _5;
36+
debug x11 => _5;
3737
}
3838
scope 4 {
39-
debug x => _6;
39+
debug x12 => _6;
4040
}
4141
}
4242

0 commit comments

Comments
 (0)