Skip to content

Commit 314d48f

Browse files
committed
Fix ownership of UnconditionalCheckedCastValue.
1 parent ff5b2f7 commit 314d48f

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

include/swift/SIL/SILNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
287287
// accross the cast (which reads the type metadata). With Semantic SIL we
288288
// should be able to move this back to None - it should model the scoping
289289
// and forbid the compiler from moving the ultimate retain.
290-
INST(UnconditionalCheckedCastValueInst, ConversionInst, unconditional_checked_cast_value, MayRead, DoesNotRelease)
290+
INST(UnconditionalCheckedCastValueInst, ConversionInst, unconditional_checked_cast_value, MayRead, MayRelease)
291291
INST(UnconditionalCheckedCastInst, ConversionInst, unconditional_checked_cast, MayRead, DoesNotRelease)
292292
VALUE_RANGE(ConversionInst, UpcastInst, UnconditionalCheckedCastInst)
293293
INST(IsNonnullInst, SILInstruction, is_nonnull, None, DoesNotRelease)

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ static bool isOwnershipForwardingValueKind(ValueKind K) {
202202
case ValueKind::RefToBridgeObjectInst:
203203
case ValueKind::BridgeObjectToRefInst:
204204
case ValueKind::UnconditionalCheckedCastInst:
205-
case ValueKind::UnconditionalCheckedCastValueInst:
206205
case ValueKind::TupleExtractInst:
207206
case ValueKind::StructExtractInst:
208207
case ValueKind::UncheckedEnumDataInst:
@@ -529,6 +528,7 @@ CONSTANT_OWNERSHIP_INST(Trivial, false, DeallocValueBuffer)
529528
SHOULD_CHECK_FOR_DATAFLOW_VIOLATIONS}; \
530529
}
531530
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, CheckedCastValueBranch)
531+
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, UnconditionalCheckedCastValue)
532532
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, InitExistentialValue)
533533
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, DeinitExistentialValue)
534534
#undef CONSTANT_OR_TRIVIAL_OWNERSHIP_INST
@@ -658,7 +658,6 @@ FORWARD_ANY_OWNERSHIP_INST(ConvertFunction)
658658
FORWARD_ANY_OWNERSHIP_INST(RefToBridgeObject)
659659
FORWARD_ANY_OWNERSHIP_INST(BridgeObjectToRef)
660660
FORWARD_ANY_OWNERSHIP_INST(UnconditionalCheckedCast)
661-
FORWARD_ANY_OWNERSHIP_INST(UnconditionalCheckedCastValue)
662661
FORWARD_ANY_OWNERSHIP_INST(MarkUninitialized)
663662
FORWARD_ANY_OWNERSHIP_INST(UncheckedEnumData)
664663
#undef FORWARD_ANY_OWNERSHIP_INST

lib/SIL/ValueOwnershipKindClassifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ CONSTANT_OWNERSHIP_INST(Owned, PartialApply)
4545
CONSTANT_OWNERSHIP_INST(Owned, StrongPin)
4646
CONSTANT_OWNERSHIP_INST(Owned, ThinToThickFunction)
4747
CONSTANT_OWNERSHIP_INST(Owned, InitExistentialValue)
48-
CONSTANT_OWNERSHIP_INST(Owned, UnconditionalCheckedCastValue)
4948

5049
// One would think that these /should/ be unowned. In truth they are owned since
5150
// objc metatypes do not go through the retain/release fast path. In their
@@ -132,6 +131,7 @@ CONSTANT_OWNERSHIP_INST(Unowned, UnownedToRef)
132131
}
133132
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Guaranteed, StructExtract)
134133
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Guaranteed, TupleExtract)
134+
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, UnconditionalCheckedCastValue)
135135
#undef CONSTANT_OR_TRIVIAL_OWNERSHIP_INST
136136

137137
// These are instructions that do not have any result, so we should never reach

test/SIL/ownership-verifier/opaque_use_verifier.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,25 @@ bb0(%0 : @guaranteed $T):
5757
destroy_value %1 : $T
5858
return %4 : $T
5959
}
60+
61+
public protocol AnyObject : class {}
62+
63+
sil @takeType : $@convention(thin) (@thick AnyObject.Type) -> () {
64+
bb0(%0 : @trivial $@thick AnyObject.Type):
65+
%18 = tuple ()
66+
return %18 : $()
67+
}
68+
69+
// Test an unconditional cast from an owned value to a trivial value.
70+
sil @castToTrivial : $@convention(thin) (@owned AnyObject) -> () {
71+
bb0(%0 : @owned $AnyObject):
72+
%6 = function_ref @takeType : $@convention(thin) (@thick AnyObject.Type) -> ()
73+
%8 = begin_borrow %0 : $AnyObject
74+
%9 = copy_value %8 : $AnyObject
75+
%10 = unconditional_checked_cast_value take_always %9 : $AnyObject to $@thick AnyObject.Type
76+
%11 = apply %6(%10) : $@convention(thin) (@thick AnyObject.Type) -> ()
77+
end_borrow %8 from %0 : $AnyObject, $AnyObject
78+
destroy_value %0 : $AnyObject
79+
%18 = tuple ()
80+
return %18 : $()
81+
}

0 commit comments

Comments
 (0)