@@ -535,3 +535,70 @@ bb0(%arg : $BiggerStruct):
535
535
%ret = tuple ()
536
536
return %ret : $()
537
537
}
538
+
539
+ enum Either {
540
+ case left(Builtin.Int64)
541
+ case right(Builtin.Int64)
542
+ }
543
+
544
+ // Make sure that we properly handle failure default cases.
545
+ sil [ossa] @switch_enum_test_callee_1 : $@convention(thin) () -> Builtin.Int64 {
546
+ bb0:
547
+ %0 = integer_literal $Builtin.Int64, 0
548
+ %1 = enum $Either, #Either.left!enumelt.1, %0 : $Builtin.Int64
549
+ switch_enum %1 : $Either, case #Either.left!enumelt.1: bb1, default bb2
550
+
551
+ bb1(%2 : $Builtin.Int64):
552
+ br bb3(%2 : $Builtin.Int64)
553
+
554
+ bb2(%3 : $Either):
555
+ %4 = integer_literal $Builtin.Int64, 1
556
+ br bb3(%4 : $Builtin.Int64)
557
+
558
+ bb3(%5 : $Builtin.Int64):
559
+ return %5 : $Builtin.Int64
560
+ }
561
+
562
+ sil [ossa] @switch_enum_test_callee_2 : $@convention(thin) () -> Builtin.Int64 {
563
+ bb0:
564
+ %0 = integer_literal $Builtin.Int64, 0
565
+ %1 = enum $Either, #Either.left!enumelt.1, %0 : $Builtin.Int64
566
+ // Make sure we go down the bad path.
567
+ switch_enum %1 : $Either, case #Either.right!enumelt.1: bb4, default bb5
568
+
569
+ bb4(%7 : $Builtin.Int64):
570
+ br bb6(%7 : $Builtin.Int64)
571
+
572
+ bb5(%8 : $Either):
573
+ %9 = unchecked_enum_data %8 : $Either, #Either.right!enumelt.1
574
+ br bb6(%9 : $Builtin.Int64)
575
+
576
+ bb6(%10 : $Builtin.Int64):
577
+ return %10 : $Builtin.Int64
578
+ }
579
+
580
+ sil [ossa] @switch_enum_test_caller : $@convention(thin) () -> () {
581
+ bb0:
582
+ %0 = function_ref @switch_enum_test_callee_1 : $@convention(thin) () -> Builtin.Int64
583
+ %0a = function_ref @switch_enum_test_callee_2 : $@convention(thin) () -> Builtin.Int64
584
+ %2 = apply %0() : $@convention(thin) () -> Builtin.Int64
585
+ %3 = apply %0a() : $@convention(thin) () -> Builtin.Int64
586
+ %str = string_literal utf8 ""
587
+ %resultPositive = integer_literal $Builtin.Int64, 0
588
+ %resultNegative = integer_literal $Builtin.Int64, 1
589
+ %cmp1Positive = builtin "cmp_eq_Int64"(%2 : $Builtin.Int64, %resultPositive : $Builtin.Int64) : $Builtin.Int1
590
+ builtin "poundAssert"(%cmp1Positive : $Builtin.Int1, %str : $Builtin.RawPointer) : $()
591
+ // Make sure we simplified down the bb1 path.
592
+ %cmp2Positive = builtin "cmp_eq_Int64"(%3 : $Builtin.Int64, %resultPositive : $Builtin.Int64) : $Builtin.Int1
593
+ builtin "poundAssert"(%cmp2Positive : $Builtin.Int1, %str : $Builtin.RawPointer) : $()
594
+
595
+ %cmp1Negative = builtin "cmp_eq_Int64"(%2 : $Builtin.Int64, %resultNegative : $Builtin.Int64) : $Builtin.Int1
596
+ // expected-error @+1 {{assertion failed}}
597
+ builtin "poundAssert"(%cmp1Negative : $Builtin.Int1, %str : $Builtin.RawPointer) : $()
598
+ %cmp2Negative = builtin "cmp_eq_Int64"(%3 : $Builtin.Int64, %resultNegative : $Builtin.Int64) : $Builtin.Int1
599
+ // expected-error @+1 {{assertion failed}}
600
+ builtin "poundAssert"(%cmp2Negative : $Builtin.Int1, %str : $Builtin.RawPointer) : $()
601
+
602
+ %9999 = tuple()
603
+ return %9999 : $()
604
+ }
0 commit comments