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 @@ -348,8 +348,13 @@ static SILValue simplifyDeadCast(SingleValueInstruction *Cast) {
348
348
for (Operand *op : Cast->getUses ()) {
349
349
switch (op->getUser ()->getKind ()) {
350
350
case SILInstructionKind::DestroyValueInst:
351
+ break ;
351
352
case SILInstructionKind::StrongReleaseInst:
352
353
case SILInstructionKind::StrongRetainInst:
354
+ // ref-casts can cast from an Optional<Classtype>. But strong_retain/
355
+ // strong_release don't accept an optional.
356
+ if (!Cast->getOperand (0 )->getType ().isReferenceCounted (Cast->getModule ()))
357
+ return SILValue ();
353
358
break ;
354
359
default :
355
360
return SILValue ();
Original file line number Diff line number Diff line change @@ -836,6 +836,20 @@ bb0(%0 : $C1):
836
836
return %0 : $C1
837
837
}
838
838
839
+ // strong_retain/strong_release don't accept an Optional<reference>.
840
+ //
841
+ // CHECK-LABEL: sil @dontOptimizeRefCastOfOptional
842
+ // CHECK: %1 = unchecked_ref_cast %0
843
+ // CHECK: strong_retain %1
844
+ // CHECK: } // end sil function 'dontOptimizeRefCastOfOptional'
845
+ sil @dontOptimizeRefCastOfOptional : $@convention(thin) (@guaranteed Optional<C1>) -> () {
846
+ bb0(%0 : $Optional<C1>):
847
+ %1 = unchecked_ref_cast %0 : $Optional<C1> to $C1
848
+ strong_retain %1 : $C1
849
+ %3 = tuple ()
850
+ return %3 : $()
851
+ }
852
+
839
853
// CHECK-LABEL: sil @dead_end_cow_mutation
840
854
// CHECK: bb0
841
855
// CHECK-NEXT: strong_retain %0
You can’t perform that action at this time.
0 commit comments