Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 696cec3

Browse files
authoredJan 27, 2024
Rollup merge of rust-lang#119759 - sfzhu93:master, r=cjgillot
Add FileCheck annotations to dataflow-const-prop tests part of rust-lang#116971. A few shadowing variable names are changed, so that it is easier to match the variable names in MIR using FileCheck syntax. Also, there's a FIXME in [enum.rs](https://github.com/rust-lang/rust/pull/119759/files#diff-7621f55327838e489a95ac99ae1e6126b37c57aff582594e6bee9d7e7e56fc58) because the MIR looks suspicious to me. It has been explained in the comments. r? cjgillot
2 parents b93aba2 + 65b1083 commit 696cec3

32 files changed

+394
-87
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: DataflowConstProp
43
// EMIT_MIR_FOR_EACH_BIT_WIDTH
54

65
// EMIT_MIR array_index.main.DataflowConstProp.diff
6+
7+
// CHECK-LABEL: fn main() -> () {
78
fn main() {
9+
// CHECK: let mut [[array_lit:_.*]]: [u32; 4];
10+
// CHECK: debug x => [[x:_.*]];
11+
12+
// CHECK: [[array_lit]] = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
13+
// CHECK-NOT: {{_.*}} = Len(
14+
// CHECK-NOT: {{_.*}} = Lt(
15+
// CHECK-NOT: assert(move _
16+
// CHECK: {{_.*}} = const 4_usize;
17+
// CHECK: {{_.*}} = const true;
18+
// CHECK: assert(const true
19+
// CHECK: [[x]] = [[array_lit]][2 of 3];
820
let x: u32 = [0, 1, 2, 3][2];
921
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR boolean_identities.test.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn test(
56
pub fn test(x: bool, y: bool) -> bool {
7+
// CHECK-NOT: BitAnd(
8+
// CHECK-NOT: BitOr(
69
(y | true) & (x & false)
10+
// CHECK: _0 = const false;
11+
// CHECK-NOT: BitAnd(
12+
// CHECK-NOT: BitOr(
713
}
814

15+
// CHECK-LABEL: fn main(
916
fn main() {
1017
test(true, false);
1118
}
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR cast.main.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn main(
56
fn main() {
7+
// CHECK: debug a => [[a:_.*]];
8+
// CHECK: debug b => [[b:_.*]];
9+
10+
// CHECK: [[a]] = const 257_i32;
611
let a = 257;
12+
// CHECK: [[b]] = const 2_u8;
713
let b = a as u8 + 1;
814
}
+18-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// compile-flags: -Coverflow-checks=on
43
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
54

65
// EMIT_MIR checked.main.DataflowConstProp.diff
76
#[allow(arithmetic_overflow)]
7+
8+
// CHECK-LABEL: fn main(
89
fn main() {
10+
// CHECK: debug a => [[a:_.*]];
11+
// CHECK: debug b => [[b:_.*]];
12+
// CHECK: debug c => [[c:_.*]];
13+
// CHECK: debug d => [[d:_.*]];
14+
// CHECK: debug e => [[e:_.*]];
15+
16+
// CHECK: [[a]] = const 1_i32;
917
let a = 1;
18+
19+
// CHECK: [[b]] = const 2_i32;
1020
let b = 2;
21+
22+
// CHECK: assert(!const false,
23+
// CHECK: [[c]] = const 3_i32;
1124
let c = a + b;
1225

26+
// CHECK: [[d]] = const _;
1327
let d = i32::MAX;
28+
29+
// CHECK: assert(!const true,
30+
// CHECK: [[e]] = const i32::MIN;
1431
let e = d + 1;
1532
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// compile-flags: -Zmir-enable-passes=+GVN,+Inline
43
// ignore-debug assertions change the output MIR
54
// EMIT_MIR_FOR_EACH_BIT_WIDTH
65
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
76

7+
// This test is to check ICE in issue [#115789](https://github.com/rust-lang/rust/issues/115789).
8+
89
struct A {
910
foo: Box<[bool]>,
1011
}
1112

1213
// EMIT_MIR default_boxed_slice.main.GVN.diff
1314
// EMIT_MIR default_boxed_slice.main.DataflowConstProp.diff
15+
16+
// CHECK-LABEL: fn main(
1417
fn main() {
1518
// ConstProp will create a constant of type `Box<[bool]>`.
19+
// FIXME: it is not yet a constant.
20+
1621
// Verify that `DataflowConstProp` does not ICE trying to dereference it directly.
22+
23+
// CHECK: debug a => [[a:_.*]];
24+
// We may check other inlined functions as well...
25+
26+
// CHECK: {{_.*}} = Box::<[bool]>(
27+
// FIXME: should be `{{_.*}} = const Box::<[bool]>`
1728
let a: A = A { foo: Box::default() };
1829
}

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

+2-2
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.constant.DataflowConstProp.64bit.diff

+2-2
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

+1-1
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

+1-1
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

+70-10
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,76 @@ 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: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
24+
// CHECK: [[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: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
40+
// CHECK: [[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: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
59+
// CHECK: [[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+
69+
// CHECK: switchInt({{move _.*}}) -> {{.*}}
70+
// FIXME: add checks for x2. Currently, their MIRs are not symmetric in the two
71+
// switch branches.
72+
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
73+
// get by printing MIR directly. It is better to check if there are any bugs in the
74+
// MIR passes around this stage.
75+
let x2 = match e2 { E::V1(x21) => x21, E::V2(x22) => x22 };
3776
}
3877

3978
#[rustc_layout_scalar_valid_range_start(1)]
4079
#[rustc_nonnull_optimization_guaranteed]
4180
struct NonZeroUsize(usize);
4281

4382
// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff
83+
84+
// CHECK-LABEL: fn mutate_discriminant(
4485
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
4586
fn mutate_discriminant() -> u8 {
4687
mir!(
@@ -50,7 +91,11 @@ fn mutate_discriminant() -> u8 {
5091
// This assignment overwrites the niche in which the discriminant is stored.
5192
place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize;
5293
// So we cannot know the value of this discriminant.
94+
95+
// CHECK: [[a:_.*]] = discriminant({{_.*}});
5396
let a = Discriminant(x);
97+
98+
// CHECK: switchInt([[a]]) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
5499
match a {
55100
0 => bb1,
56101
_ => bad,
@@ -68,18 +113,33 @@ fn mutate_discriminant() -> u8 {
68113
}
69114

70115
// EMIT_MIR enum.multiple.DataflowConstProp.diff
116+
// CHECK-LABEL: fn multiple(
71117
fn multiple(x: bool, i: u8) {
118+
// CHECK: debug x => [[x:_.*]];
119+
// CHECK: debug e => [[e:_.*]];
120+
// CHECK: debug x2 => [[x2:_.*]];
121+
// CHECK: debug y => [[y:_.*]];
72122
let e = if x {
123+
// CHECK: [[e]] = Option::<u8>::Some(move {{_.*}});
73124
Some(i)
74125
} else {
126+
// CHECK: [[e]] = Option::<u8>::None;
75127
None
76128
};
77129
// The dataflow state must have:
78130
// discriminant(e) => Top
79131
// (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;
132+
// CHECK: [[x2]] = const 0_u8;
133+
// CHECK: [[some:_.*]] = (({{_.*}} as Some).0: u8)
134+
// CHECK: [[x2]] = [[some]];
135+
let x2 = match e { Some(i) => i, None => 0 };
136+
137+
// Therefore, `x2` should be `Top` here, and no replacement shall happen.
138+
139+
// CHECK-NOT: [[y]] = const
140+
// CHECK: [[y]] = [[x2]];
141+
// CHECK-NOT: [[y]] = const
142+
let y = x2;
83143
}
84144

85145
fn main() {

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

+2-2
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

+2-2
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

+8-8
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)
Please sign in to comment.