Skip to content

Fix ownership of UnconditionalCheckedCastValue. #11316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
// accross the cast (which reads the type metadata). With Semantic SIL we
// should be able to move this back to None - it should model the scoping
// and forbid the compiler from moving the ultimate retain.
INST(UnconditionalCheckedCastValueInst, ConversionInst, unconditional_checked_cast_value, MayRead, DoesNotRelease)
INST(UnconditionalCheckedCastValueInst, ConversionInst, unconditional_checked_cast_value, MayRead, MayRelease)
INST(UnconditionalCheckedCastInst, ConversionInst, unconditional_checked_cast, MayRead, DoesNotRelease)
VALUE_RANGE(ConversionInst, UpcastInst, UnconditionalCheckedCastInst)
INST(IsNonnullInst, SILInstruction, is_nonnull, None, DoesNotRelease)
Expand Down
3 changes: 1 addition & 2 deletions lib/SIL/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ static bool isOwnershipForwardingValueKind(ValueKind K) {
case ValueKind::RefToBridgeObjectInst:
case ValueKind::BridgeObjectToRefInst:
case ValueKind::UnconditionalCheckedCastInst:
case ValueKind::UnconditionalCheckedCastValueInst:
case ValueKind::TupleExtractInst:
case ValueKind::StructExtractInst:
case ValueKind::UncheckedEnumDataInst:
Expand Down Expand Up @@ -529,6 +528,7 @@ CONSTANT_OWNERSHIP_INST(Trivial, false, DeallocValueBuffer)
SHOULD_CHECK_FOR_DATAFLOW_VIOLATIONS}; \
}
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, CheckedCastValueBranch)
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, UnconditionalCheckedCastValue)
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, InitExistentialValue)
CONSTANT_OR_TRIVIAL_OWNERSHIP_INST(Owned, true, DeinitExistentialValue)
#undef CONSTANT_OR_TRIVIAL_OWNERSHIP_INST
Expand Down Expand Up @@ -658,7 +658,6 @@ FORWARD_ANY_OWNERSHIP_INST(ConvertFunction)
FORWARD_ANY_OWNERSHIP_INST(RefToBridgeObject)
FORWARD_ANY_OWNERSHIP_INST(BridgeObjectToRef)
FORWARD_ANY_OWNERSHIP_INST(UnconditionalCheckedCast)
FORWARD_ANY_OWNERSHIP_INST(UnconditionalCheckedCastValue)
FORWARD_ANY_OWNERSHIP_INST(MarkUninitialized)
FORWARD_ANY_OWNERSHIP_INST(UncheckedEnumData)
#undef FORWARD_ANY_OWNERSHIP_INST
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/ValueOwnershipKindClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ CONSTANT_OWNERSHIP_INST(Owned, PartialApply)
CONSTANT_OWNERSHIP_INST(Owned, StrongPin)
CONSTANT_OWNERSHIP_INST(Owned, ThinToThickFunction)
CONSTANT_OWNERSHIP_INST(Owned, InitExistentialValue)
CONSTANT_OWNERSHIP_INST(Owned, UnconditionalCheckedCastValue)

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

// These are instructions that do not have any result, so we should never reach
Expand Down
22 changes: 22 additions & 0 deletions test/SIL/ownership-verifier/opaque_use_verifier.sil
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@ bb0(%0 : @guaranteed $T):
destroy_value %1 : $T
return %4 : $T
}

public protocol AnyObject : class {}

sil @takeType : $@convention(thin) (@thick AnyObject.Type) -> () {
bb0(%0 : @trivial $@thick AnyObject.Type):
%18 = tuple ()
return %18 : $()
}

// Test an unconditional cast from an owned value to a trivial value.
sil @castToTrivial : $@convention(thin) (@owned AnyObject) -> () {
bb0(%0 : @owned $AnyObject):
%6 = function_ref @takeType : $@convention(thin) (@thick AnyObject.Type) -> ()
%8 = begin_borrow %0 : $AnyObject
%9 = copy_value %8 : $AnyObject
%10 = unconditional_checked_cast_value take_always %9 : $AnyObject to $@thick AnyObject.Type
%11 = apply %6(%10) : $@convention(thin) (@thick AnyObject.Type) -> ()
end_borrow %8 from %0 : $AnyObject, $AnyObject
destroy_value %0 : $AnyObject
%18 = tuple ()
return %18 : $()
}