File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
lib/SILOptimizer/Analysis Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -341,8 +341,13 @@ static SILValue simplifyDeadCast(SingleValueInstruction *Cast) {
341
341
for (Operand *op : Cast->getUses ()) {
342
342
switch (op->getUser ()->getKind ()) {
343
343
case SILInstructionKind::DestroyValueInst:
344
+ break ;
344
345
case SILInstructionKind::StrongReleaseInst:
345
346
case SILInstructionKind::StrongRetainInst:
347
+ // ref-casts can cast from an Optional<Classtype>. But strong_retain/
348
+ // strong_release don't accept an optional.
349
+ if (!Cast->getOperand (0 )->getType ().isReferenceCounted (Cast->getModule ()))
350
+ return SILValue ();
346
351
break ;
347
352
default :
348
353
return SILValue ();
Original file line number Diff line number Diff line change @@ -821,6 +821,20 @@ bb0(%0 : $C1):
821
821
return %0 : $C1
822
822
}
823
823
824
+ // strong_retain/strong_release don't accept an Optional<reference>.
825
+ //
826
+ // CHECK-LABEL: sil @dontOptimizeRefCastOfOptional
827
+ // CHECK: %1 = unchecked_ref_cast %0
828
+ // CHECK: strong_retain %1
829
+ // CHECK: } // end sil function 'dontOptimizeRefCastOfOptional'
830
+ sil @dontOptimizeRefCastOfOptional : $@convention(thin) (@guaranteed Optional<C1>) -> () {
831
+ bb0(%0 : $Optional<C1>):
832
+ %1 = unchecked_ref_cast %0 : $Optional<C1> to $C1
833
+ strong_retain %1 : $C1
834
+ %3 = tuple ()
835
+ return %3 : $()
836
+ }
837
+
824
838
// CHECK-LABEL: sil @dead_end_cow_mutation
825
839
// CHECK: bb0
826
840
// CHECK-NEXT: strong_retain %0
You can’t perform that action at this time.
0 commit comments