Skip to content

Commit ae2e211

Browse files
committed
FileCheck uninhabited_enum_branching.
1 parent cb91890 commit ae2e211

7 files changed

+126
-245
lines changed

tests/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff renamed to tests/mir-opt/uninhabited_enum_branching.byref.UninhabitedEnumBranching.diff

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
- // MIR for `main` before UninhabitedEnumBranching
2-
+ // MIR for `main` after UninhabitedEnumBranching
1+
- // MIR for `byref` before UninhabitedEnumBranching
2+
+ // MIR for `byref` after UninhabitedEnumBranching
33

4-
fn main() -> () {
4+
fn byref() -> () {
55
let mut _0: ();
66
let _1: Plop;
7-
let mut _2: Test1;
7+
let mut _2: Test3;
88
let _3: &str;
9-
let mut _4: &Test1;
9+
let mut _4: &Test3;
1010
let mut _5: isize;
1111
let _6: &str;
1212
let _7: &str;
@@ -23,12 +23,12 @@
2323
bb0: {
2424
StorageLive(_1);
2525
StorageLive(_2);
26-
_2 = Test1::C;
27-
_1 = Plop { xx: const 51_u32, test1: move _2 };
26+
_2 = Test3::C;
27+
_1 = Plop { xx: const 51_u32, test3: move _2 };
2828
StorageDead(_2);
2929
StorageLive(_3);
3030
StorageLive(_4);
31-
_4 = &(_1.1: Test1);
31+
_4 = &(_1.1: Test3);
3232
_5 = discriminant((*_4));
3333
- switchInt(move _5) -> [0: bb3, 1: bb4, 2: bb5, 3: bb1, otherwise: bb2];
3434
+ switchInt(move _5) -> [0: bb12, 1: bb12, 2: bb5, 3: bb1, otherwise: bb12];
@@ -71,7 +71,7 @@
7171
StorageDead(_4);
7272
StorageDead(_3);
7373
StorageLive(_9);
74-
_10 = discriminant((_1.1: Test1));
74+
_10 = discriminant((_1.1: Test3));
7575
- switchInt(move _10) -> [0: bb8, 1: bb9, 2: bb10, 3: bb7, otherwise: bb2];
7676
+ switchInt(move _10) -> [0: bb12, 1: bb12, 2: bb10, 3: bb7, otherwise: bb12];
7777
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
- // MIR for `custom_discriminant` before UninhabitedEnumBranching
2+
+ // MIR for `custom_discriminant` after UninhabitedEnumBranching
3+
4+
fn custom_discriminant() -> () {
5+
let mut _0: ();
6+
let _1: &str;
7+
let mut _2: Test2;
8+
let mut _3: isize;
9+
let _4: &str;
10+
11+
bb0: {
12+
StorageLive(_1);
13+
StorageLive(_2);
14+
_2 = Test2::D;
15+
_3 = discriminant(_2);
16+
- switchInt(move _3) -> [4: bb3, 5: bb1, otherwise: bb2];
17+
+ switchInt(move _3) -> [4: bb3, 5: bb1, otherwise: bb5];
18+
}
19+
20+
bb1: {
21+
StorageLive(_4);
22+
_4 = const "E";
23+
_1 = &(*_4);
24+
StorageDead(_4);
25+
goto -> bb4;
26+
}
27+
28+
bb2: {
29+
unreachable;
30+
}
31+
32+
bb3: {
33+
_1 = const "D";
34+
goto -> bb4;
35+
}
36+
37+
bb4: {
38+
StorageDead(_2);
39+
StorageDead(_1);
40+
_0 = const ();
41+
return;
42+
+ }
43+
+
44+
+ bb5: {
45+
+ unreachable;
46+
}
47+
}
48+

tests/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir

-65
This file was deleted.
+64-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// skip-filecheck
2-
enum Empty { }
1+
// unit-test: UninhabitedEnumBranching
2+
enum Empty {}
33

44
// test matching an enum with uninhabited variants
55
enum Test1 {
66
A(Empty),
77
B(Empty),
8-
C
8+
C,
99
}
1010

1111
// test an enum where the discriminants don't match the variant indexes
@@ -15,17 +15,75 @@ enum Test2 {
1515
E = 5,
1616
}
1717

18-
// EMIT_MIR uninhabited_enum_branching.main.UninhabitedEnumBranching.diff
19-
// EMIT_MIR uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir
20-
fn main() {
18+
// test matching an enum with uninhabited variants and multiple inhabited
19+
enum Test3 {
20+
A(Empty),
21+
B(Empty),
22+
C,
23+
D,
24+
}
25+
26+
struct Plop {
27+
xx: u32,
28+
test3: Test3,
29+
}
30+
31+
// EMIT_MIR uninhabited_enum_branching.simple.UninhabitedEnumBranching.diff
32+
fn simple() {
33+
// CHECK-LABEL: fn simple(
34+
// CHECK: [[discr:_.*]] = discriminant(
35+
// CHECK: switchInt(move [[discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb1, otherwise: [[unreachable]]];
36+
// CHECK: [[unreachable]]: {
37+
// CHECK-NEXT: unreachable;
2138
match Test1::C {
2239
Test1::A(_) => "A(Empty)",
2340
Test1::B(_) => "B(Empty)",
2441
Test1::C => "C",
2542
};
43+
}
2644

45+
// EMIT_MIR uninhabited_enum_branching.custom_discriminant.UninhabitedEnumBranching.diff
46+
fn custom_discriminant() {
47+
// CHECK-LABEL: fn custom_discriminant(
48+
// CHECK: [[discr:_.*]] = discriminant(
49+
// CHECK: switchInt(move [[discr]]) -> [4: bb3, 5: bb1, otherwise: bb5];
50+
// CHECK: bb5: {
51+
// CHECK-NEXT: unreachable;
2752
match Test2::D {
2853
Test2::D => "D",
2954
Test2::E => "E",
3055
};
3156
}
57+
58+
// EMIT_MIR uninhabited_enum_branching.byref.UninhabitedEnumBranching.diff
59+
fn byref() {
60+
// CHECK-LABEL: fn byref(
61+
let plop = Plop { xx: 51, test3: Test3::C };
62+
63+
// CHECK: [[ref_discr:_.*]] = discriminant((*
64+
// CHECK: switchInt(move [[ref_discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb5, 3: bb1, otherwise: [[unreachable]]];
65+
match &plop.test3 {
66+
Test3::A(_) => "A(Empty)",
67+
Test3::B(_) => "B(Empty)",
68+
Test3::C => "C",
69+
Test3::D => "D",
70+
};
71+
72+
// CHECK: [[discr:_.*]] = discriminant(
73+
// CHECK: switchInt(move [[discr]]) -> [0: [[unreachable]], 1: [[unreachable]], 2: bb10, 3: bb7, otherwise: [[unreachable]]];
74+
match plop.test3 {
75+
Test3::A(_) => "A(Empty)",
76+
Test3::B(_) => "B(Empty)",
77+
Test3::C => "C",
78+
Test3::D => "D",
79+
};
80+
81+
// CHECK: [[unreachable]]: {
82+
// CHECK-NEXT: unreachable;
83+
}
84+
85+
fn main() {
86+
simple();
87+
custom_discriminant();
88+
byref();
89+
}

tests/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff renamed to tests/mir-opt/uninhabited_enum_branching.simple.UninhabitedEnumBranching.diff

+5-33
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
- // MIR for `main` before UninhabitedEnumBranching
2-
+ // MIR for `main` after UninhabitedEnumBranching
1+
- // MIR for `simple` before UninhabitedEnumBranching
2+
+ // MIR for `simple` after UninhabitedEnumBranching
33

4-
fn main() -> () {
4+
fn simple() -> () {
55
let mut _0: ();
66
let _1: &str;
77
let mut _2: Test1;
88
let mut _3: isize;
99
let _4: &str;
1010
let _5: &str;
11-
let _6: &str;
12-
let mut _7: Test2;
13-
let mut _8: isize;
14-
let _9: &str;
1511

1612
bb0: {
1713
StorageLive(_1);
1814
StorageLive(_2);
1915
_2 = Test1::C;
2016
_3 = discriminant(_2);
2117
- switchInt(move _3) -> [0: bb3, 1: bb4, 2: bb1, otherwise: bb2];
22-
+ switchInt(move _3) -> [0: bb9, 1: bb9, 2: bb1, otherwise: bb9];
18+
+ switchInt(move _3) -> [0: bb6, 1: bb6, 2: bb1, otherwise: bb6];
2319
}
2420

2521
bb1: {
@@ -50,35 +46,11 @@
5046
bb5: {
5147
StorageDead(_2);
5248
StorageDead(_1);
53-
StorageLive(_6);
54-
StorageLive(_7);
55-
_7 = Test2::D;
56-
_8 = discriminant(_7);
57-
- switchInt(move _8) -> [4: bb7, 5: bb6, otherwise: bb2];
58-
+ switchInt(move _8) -> [4: bb7, 5: bb6, otherwise: bb9];
59-
}
60-
61-
bb6: {
62-
StorageLive(_9);
63-
_9 = const "E";
64-
_6 = &(*_9);
65-
StorageDead(_9);
66-
goto -> bb8;
67-
}
68-
69-
bb7: {
70-
_6 = const "D";
71-
goto -> bb8;
72-
}
73-
74-
bb8: {
75-
StorageDead(_7);
76-
StorageDead(_6);
7749
_0 = const ();
7850
return;
7951
+ }
8052
+
81-
+ bb9: {
53+
+ bb6: {
8254
+ unreachable;
8355
}
8456
}

0 commit comments

Comments
 (0)