|
1 |
| -// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnose-unreachable -sil-print-debuginfo | %FileCheck %s |
| 1 | +// RUN: %target-sil-opt -enable-sil-ownership -enable-sil-verify-all %s -diagnose-unreachable -sil-print-debuginfo | %FileCheck %s |
2 | 2 |
|
3 | 3 | import Builtin
|
4 | 4 | import Swift
|
|
281 | 281 | enum Singleton {
|
282 | 282 | case x(Int, UnicodeScalar)
|
283 | 283 | };
|
| 284 | + |
284 | 285 | sil @constant_fold_switch_enum_with_payload : $@convention(thin) (Int, UnicodeScalar) -> (Int, UnicodeScalar) {
|
285 | 286 | bb0(%6 : $Int, %10 : $UnicodeScalar):
|
286 | 287 | %11 = tuple (%6 : $Int, %10 : $UnicodeScalar)
|
@@ -448,3 +449,56 @@ bb2(%3 : $Never):
|
448 | 449 | bb3(%4 : $Error):
|
449 | 450 | throw %4 : $Error
|
450 | 451 | }
|
| 452 | + |
| 453 | +enum Either<L, R> { |
| 454 | +case left(L) |
| 455 | +case right(R) |
| 456 | +} |
| 457 | + |
| 458 | +class Klass1 {} |
| 459 | +class Klass2 {} |
| 460 | + |
| 461 | +// CHECK-LABEL: sil [ossa] @constant_fold_diagnose_unreachable_succ_match : $@convention(thin) (@owned Klass1) -> () { |
| 462 | +// CHECK: bb0([[ARG:%.*]] : |
| 463 | +// CHECK: destroy_value [[ARG]] |
| 464 | +// CHECK: } // end sil function 'constant_fold_diagnose_unreachable_succ_match' |
| 465 | +sil [ossa] @constant_fold_diagnose_unreachable_succ_match : $@convention(thin) (@owned Klass1) -> () { |
| 466 | +bb0(%0 : @owned $Klass1): |
| 467 | + %1 = enum $Either<Klass1, Klass2>, #Either.left!enumelt.1, %0 : $Klass1 |
| 468 | + switch_enum %1 : $Either<Klass1, Klass2>, case #Either.left!enumelt.1: bb1, default bb2 |
| 469 | + |
| 470 | +bb1(%2 : @owned $Klass1): |
| 471 | + destroy_value %2 : $Klass1 |
| 472 | + br bb3 |
| 473 | + |
| 474 | +bb2(%3 : @owned $Either<Klass1, Klass2>): |
| 475 | + destroy_value %3 : $Either<Klass1, Klass2> |
| 476 | + br bb3 |
| 477 | + |
| 478 | +bb3: |
| 479 | + %9999 = tuple() |
| 480 | + return %9999 : $() |
| 481 | +} |
| 482 | + |
| 483 | +// CHECK-LABEL: sil [ossa] @constant_fold_diagnose_unreachable_default : $@convention(thin) (@owned Klass2) -> () { |
| 484 | +// CHECK: bb0([[ARG:%.*]] : |
| 485 | +// CHECK: [[ENUM:%.*]] = enum $Either<Klass1, Klass2>, #Either.right!enumelt.1, [[ARG]] |
| 486 | +// CHECK: destroy_value [[ENUM]] |
| 487 | +// CHECK: } // end sil function 'constant_fold_diagnose_unreachable_default' |
| 488 | +sil [ossa] @constant_fold_diagnose_unreachable_default : $@convention(thin) (@owned Klass2) -> () { |
| 489 | +bb0(%0 : @owned $Klass2): |
| 490 | + %1 = enum $Either<Klass1, Klass2>, #Either.right!enumelt.1, %0 : $Klass2 |
| 491 | + switch_enum %1 : $Either<Klass1, Klass2>, case #Either.left!enumelt.1: bb1, default bb2 |
| 492 | + |
| 493 | +bb1(%2 : @owned $Klass1): |
| 494 | + destroy_value %2 : $Klass1 |
| 495 | + br bb3 |
| 496 | + |
| 497 | +bb2(%3 : @owned $Either<Klass1, Klass2>): |
| 498 | + destroy_value %3 : $Either<Klass1, Klass2> |
| 499 | + br bb3 |
| 500 | + |
| 501 | +bb3: |
| 502 | + %9999 = tuple() |
| 503 | + return %9999 : $() |
| 504 | +} |
0 commit comments