mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Add FileCheck for early_otherwise_branch*.rs
This commit is contained in:
parent
31e74771f0
commit
f5c256fa0f
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
//@ unit-test: EarlyOtherwiseBranch
|
||||
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
|
||||
|
||||
@ -11,6 +10,13 @@ enum Option2<T> {
|
||||
// We can't optimize it because y may be an invalid value.
|
||||
// EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
|
||||
fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn opt1(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y) {
|
||||
(Some(a), Some(b)) => 0,
|
||||
_ => 1,
|
||||
@ -21,6 +27,13 @@ fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
|
||||
// otherwise is unreachable. We can consume the UB fact to transform back to if else pattern.
|
||||
// EMIT_MIR early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
|
||||
fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn opt2(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y) {
|
||||
(Some(a), Some(b)) => 0,
|
||||
(None, None) => 2,
|
||||
@ -31,6 +44,14 @@ fn opt2(x: Option<u32>, y: Option<u32>) -> u32 {
|
||||
// optimize despite different types
|
||||
// EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
|
||||
fn opt3(x: Option2<u32>, y: Option2<bool>) -> u32 {
|
||||
// CHECK-LABEL: fn opt3(
|
||||
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
|
||||
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y) {
|
||||
(Option2::Some(a), Option2::Some(b)) => 0,
|
||||
(Option2::None, Option2::None) => 2,
|
||||
@ -41,6 +62,14 @@ fn opt3(x: Option2<u32>, y: Option2<bool>) -> u32 {
|
||||
|
||||
// EMIT_MIR early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff
|
||||
fn opt4(x: Option2<u32>, y: Option2<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn opt4(
|
||||
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
|
||||
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y) {
|
||||
(Option2::Some(a), Option2::Some(b)) => 0,
|
||||
(Option2::None, Option2::None) => 2,
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
//@ unit-test: EarlyOtherwiseBranch
|
||||
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
|
||||
|
||||
@ -12,6 +11,13 @@ enum Option2<T> {
|
||||
// otherwise is unreachable. We can consume the UB fact to transform back to if else pattern.
|
||||
// EMIT_MIR early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff
|
||||
fn opt1(x: Option<u32>, y: Option<u32>, z: Option<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn opt1(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y, z) {
|
||||
(Some(a), Some(b), Some(c)) => 0,
|
||||
(None, None, None) => 2,
|
||||
@ -21,6 +27,14 @@ fn opt1(x: Option<u32>, y: Option<u32>, z: Option<u32>) -> u32 {
|
||||
|
||||
// EMIT_MIR early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff
|
||||
fn opt2(x: Option2<u32>, y: Option2<u32>, z: Option2<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn opt2(
|
||||
// CHECK: let mut [[CMP_LOCAL:_.*]]: bool;
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[LOCAL2:_.*]] = discriminant({{.*}});
|
||||
// CHECK: [[CMP_LOCAL]] = Ne([[LOCAL1]], move [[LOCAL2]]);
|
||||
// CHECK: switchInt(move [[CMP_LOCAL]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y, z) {
|
||||
(Option2::Some(a), Option2::Some(b), Option2::Some(c)) => 0,
|
||||
(Option2::None, Option2::None, Option2::None) => 2,
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
//@ unit-test: EarlyOtherwiseBranch
|
||||
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
|
||||
|
||||
@ -20,6 +19,13 @@ pub extern "C" fn try_sum(
|
||||
x: &ViewportPercentageLength,
|
||||
other: &ViewportPercentageLength,
|
||||
) -> Result<ViewportPercentageLength, ()> {
|
||||
// CHECK-LABEL: fn try_sum(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
use self::ViewportPercentageLength::*;
|
||||
Ok(match (x, other) {
|
||||
(&Vw(one), &Vw(other)) => Vw(one + other),
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
//@ unit-test: EarlyOtherwiseBranch
|
||||
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
|
||||
|
||||
@ -7,6 +6,13 @@
|
||||
|
||||
// EMIT_MIR early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff
|
||||
fn noopt1(x: Option<u32>, y: Option<u32>) -> u32 {
|
||||
// CHECK-LABEL: fn noopt1(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match (x, y) {
|
||||
(Some(a), Some(b)) => 0,
|
||||
(Some(a), None) => 1,
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
//@ unit-test: EarlyOtherwiseBranch
|
||||
//@ compile-flags: -Zmir-enable-passes=+UnreachableEnumBranching
|
||||
|
||||
@ -12,12 +11,26 @@ enum E<'a> {
|
||||
|
||||
// EMIT_MIR early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
|
||||
fn no_downcast(e: &E) -> u32 {
|
||||
// CHECK-LABEL: fn no_downcast(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
if let E::Some(E::Some(_)) = e { 1 } else { 2 }
|
||||
}
|
||||
|
||||
// SAFETY: if `a` is `Some`, `b` must point to a valid, initialized value
|
||||
// EMIT_MIR early_otherwise_branch_soundness.no_deref_ptr.EarlyOtherwiseBranch.diff
|
||||
unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
|
||||
// CHECK-LABEL: fn no_deref_ptr(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: [[LOCAL1:_.*]] = discriminant({{.*}});
|
||||
// CHECK-NOT: Ne
|
||||
// CHECK-NOT: discriminant
|
||||
// CHECK: switchInt(move [[LOCAL1]]) -> [
|
||||
// CHECK-NEXT: }
|
||||
match a {
|
||||
// `*b` being correct depends on `a == Some(_)`
|
||||
Some(_) => match *b {
|
||||
|
Loading…
Reference in New Issue
Block a user