Skip to content

Commit 72639be

Browse files
committed
[SILVerifier] UnmanagedToRef and RefToUnmanaged must be loadable
1 parent c45d659 commit 72639be

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,6 +4901,9 @@ class ReferenceStorageType : public TypeBase {
49014901
}
49024902
}
49034903

4904+
/// Is this storage type known to be loadable in the given resilience scope?
4905+
bool isLoadable(ResilienceExpansion resilience) const;
4906+
49044907
// Implement isa/cast/dyncast/etc.
49054908
static bool classof(const TypeBase *T) {
49064909
return T->getKind() >= TypeKind::First_ReferenceStorageType &&
@@ -4929,10 +4932,6 @@ class UnownedStorageType : public ReferenceStorageType {
49294932
ReferenceStorageType::get(referent, ReferenceOwnership::Unowned, C));
49304933
}
49314934

4932-
/// Is this unowned storage type known to be loadable within the given
4933-
/// resilience scope?
4934-
bool isLoadable(ResilienceExpansion resilience) const;
4935-
49364935
// Implement isa/cast/dyncast/etc.
49374936
static bool classof(const TypeBase *T) {
49384937
return T->getKind() == TypeKind::UnownedStorage;

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,7 @@ bool Type::isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic) const {
40234023
return false;
40244024
}
40254025

4026-
bool UnownedStorageType::isLoadable(ResilienceExpansion resilience) const {
4026+
bool ReferenceStorageType::isLoadable(ResilienceExpansion resilience) const {
40274027
return getReferentType()->usesNativeReferenceCounting(resilience);
40284028
}
40294029

lib/SIL/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
33253325
auto operandType = I->getOperand()->getType().getSwiftRValueType();
33263326
auto resultType = requireObjectType(UnmanagedStorageType, I,
33273327
"Result of ref_to_unmanaged");
3328+
require(resultType->isLoadable(ResilienceExpansion::Maximal),
3329+
"ref_to_unmanaged requires unowned type to be loadable");
33283330
require(resultType.getReferentType() == operandType,
33293331
"Result of ref_to_unmanaged does not have the "
33303332
"operand's type as its referent type");
@@ -3334,6 +3336,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
33343336
auto operandType = requireObjectType(UnmanagedStorageType,
33353337
I->getOperand(),
33363338
"Operand of unmanaged_to_ref");
3339+
require(operandType->isLoadable(ResilienceExpansion::Maximal),
3340+
"unmanaged_to_ref requires unowned type to be loadable");
33373341
requireReferenceStorageCapableValue(I, "Result of unmanaged_to_ref");
33383342
auto resultType = I->getType().getSwiftRValueType();
33393343
require(operandType.getReferentType() == resultType,

0 commit comments

Comments
 (0)