Skip to content

Commit f5c256f

Browse files
committed
Add FileCheck for early_otherwise_branch*.rs
1 parent 31e7477 commit f5c256f

5 files changed

+73
-5
lines changed

tests/mir-opt/early_otherwise_branch.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ unit-test: EarlyOtherwiseBranch
32
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
43

@@ -11,6 +10,13 @@ enum Option2<T> {
1110
// We can't optimize it because y may be an invalid value.
1211
// EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
1312
fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
13+
// CHECK-LABEL: fn opt1(
14+
// CHECK: bb0: {
15+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
16+
// CHECK-NOT: Ne
17+
// CHECK-NOT: discriminant
18+
// CHECK: switchInt(move [[LOCAL1]]) -> [
19+
// CHECK-NEXT: }
1420
match (x, y) {
1521
(Some(a), Some(b)) => 0,
1622
_ => 1,
@@ -21,6 +27,13 @@ fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
2127
// otherwise is unreachable. We can consume the UB fact to transform back to if else pattern.
2228
// EMIT_MIR early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
2329
fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
30+
// CHECK-LABEL: fn opt2(
31+
// CHECK: bb0: {
32+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
33+
// CHECK-NOT: Ne
34+
// CHECK-NOT: discriminant
35+
// CHECK: switchInt(move [[LOCAL1]]) -> [
36+
// CHECK-NEXT: }
2437
match (x, y) {
2538
(Some(a), Some(b)) => 0,
2639
(None, None) => 2,
@@ -31,6 +44,14 @@ fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
3144
// optimize despite different types
3245
// EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
3346
fn opt3(x: Option2<u32>, y: Option2<bool>) -> u32 {
47+
// CHECK-LABEL: fn opt3(
48+
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
49+
// CHECK: bb0: {
50+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
51+
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
52+
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
53+
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
54+
// CHECK-NEXT: }
3455
match (x, y) {
3556
(Option2::Some(a), Option2::Some(b)) => 0,
3657
(Option2::None, Option2::None) => 2,
@@ -41,6 +62,14 @@ fn opt3(x: Option2<u32>, y: Option2<bool>) -> u32 {
4162

4263
// EMIT_MIR early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff
4364
fn opt4(x: Option2<u32>, y: Option2<u32>) -> u32 {
65+
// CHECK-LABEL: fn opt4(
66+
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
67+
// CHECK: bb0: {
68+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
69+
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
70+
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
71+
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
72+
// CHECK-NEXT: }
4473
match (x, y) {
4574
(Option2::Some(a), Option2::Some(b)) => 0,
4675
(Option2::None, Option2::None) => 2,

tests/mir-opt/early_otherwise_branch_3_element_tuple.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ unit-test: EarlyOtherwiseBranch
32
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
43

@@ -12,6 +11,13 @@ enum Option2<T> {
1211
// otherwise is unreachable. We can consume the UB fact to transform back to if else pattern.
1312
// EMIT_MIR early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff
1413
fn opt1(x: Option<u32>, y: Option<u32>, z: Option<u32>) -> u32 {
14+
// CHECK-LABEL: fn opt1(
15+
// CHECK: bb0: {
16+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
17+
// CHECK-NOT: Ne
18+
// CHECK-NOT: discriminant
19+
// CHECK: switchInt(move [[LOCAL1]]) -> [
20+
// CHECK-NEXT: }
1521
match (x, y, z) {
1622
(Some(a), Some(b), Some(c)) => 0,
1723
(None, None, None) => 2,
@@ -21,6 +27,14 @@ fn opt1(x: Option<u32>, y: Option<u32>, z: Option<u32>) -> u32 {
2127

2228
// EMIT_MIR early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff
2329
fn opt2(x: Option2<u32>, y: Option2<u32>, z: Option2<u32>) -> u32 {
30+
// CHECK-LABEL: fn opt2(
31+
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
32+
// CHECK: bb0: {
33+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
34+
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
35+
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
36+
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
37+
// CHECK-NEXT: }
2438
match (x, y, z) {
2539
(Option2::Some(a), Option2::Some(b), Option2::Some(c)) => 0,
2640
(Option2::None, Option2::None, Option2::None) => 2,

tests/mir-opt/early_otherwise_branch_68867.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ unit-test: EarlyOtherwiseBranch
32
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
43

@@ -20,6 +19,13 @@ pub extern "C" fn try_sum(
2019
x: &ViewportPercentageLength,
2120
other: &ViewportPercentageLength,
2221
) -> Result<ViewportPercentageLength, ()> {
22+
// CHECK-LABEL: fn try_sum(
23+
// CHECK: bb0: {
24+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
25+
// CHECK-NOT: Ne
26+
// CHECK-NOT: discriminant
27+
// CHECK: switchInt(move [[LOCAL1]]) -> [
28+
// CHECK-NEXT: }
2329
use self::ViewportPercentageLength::*;
2430
Ok(match (x, other) {
2531
(&Vw(one), &Vw(other)) => Vw(one + other),

tests/mir-opt/early_otherwise_branch_noopt.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ unit-test: EarlyOtherwiseBranch
32
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
43

@@ -7,6 +6,13 @@
76

87
// EMIT_MIR early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff
98
fn noopt1(x: Option<u32>, y: Option<u32>) -> u32 {
9+
// CHECK-LABEL: fn noopt1(
10+
// CHECK: bb0: {
11+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
12+
// CHECK-NOT: Ne
13+
// CHECK-NOT: discriminant
14+
// CHECK: switchInt(move [[LOCAL1]]) -> [
15+
// CHECK-NEXT: }
1016
match (x, y) {
1117
(Some(a), Some(b)) => 0,
1218
(Some(a), None) => 1,

tests/mir-opt/early_otherwise_branch_soundness.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ unit-test: EarlyOtherwiseBranch
32
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
43

@@ -12,12 +11,26 @@ enum E<'a> {
1211

1312
// EMIT_MIR early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
1413
fn no_downcast(e: &E) -> u32 {
14+
// CHECK-LABEL: fn no_downcast(
15+
// CHECK: bb0: {
16+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
17+
// CHECK-NOT: Ne
18+
// CHECK-NOT: discriminant
19+
// CHECK: switchInt(move [[LOCAL1]]) -> [
20+
// CHECK-NEXT: }
1521
if let E::Some(E::Some(_)) = e { 1 } else { 2 }
1622
}
1723

1824
// SAFETY: if `a` is `Some`, `b` must point to a valid, initialized value
1925
// EMIT_MIR early_otherwise_branch_soundness.no_deref_ptr.EarlyOtherwiseBranch.diff
2026
unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
27+
// CHECK-LABEL: fn no_deref_ptr(
28+
// CHECK: bb0: {
29+
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
30+
// CHECK-NOT: Ne
31+
// CHECK-NOT: discriminant
32+
// CHECK: switchInt(move [[LOCAL1]]) -> [
33+
// CHECK-NEXT: }
2134
match a {
2235
// `*b` being correct depends on `a == Some(_)`
2336
Some(_) => match *b {

0 commit comments

Comments
 (0)