Skip to content

Commit 3265808

Browse files
authored
Merge pull request #10830 from gottesmm/ownership_verifier_class_method
2 parents b307e9b + 56acc6d commit 3265808

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,24 @@ ACCEPTS_ANY_OWNERSHIP_INST(ValueMetatype)
551551
ACCEPTS_ANY_OWNERSHIP_INST(UncheckedOwnershipConversion)
552552
#undef ACCEPTS_ANY_OWNERSHIP_INST
553553

554+
// Trivial if trivial typed, otherwise must accept owned?
555+
#define ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE( \
556+
SHOULD_CHECK_FOR_DATAFLOW_VIOLATIONS, INST) \
557+
OwnershipUseCheckerResult \
558+
OwnershipCompatibilityUseChecker::visit##INST##Inst(INST##Inst *I) { \
559+
assert(I->getNumOperands() && "Expected to have non-zero operands"); \
560+
if (getType().is<AnyMetatypeType>()) { \
561+
return {true, false}; \
562+
} \
563+
assert(!isAddressOrTrivialType() && \
564+
"Shouldn't have an address or a non trivial type"); \
565+
bool compatible = getOwnershipKind() == ValueOwnershipKind::Any || \
566+
!compatibleWithOwnership(ValueOwnershipKind::Trivial); \
567+
return {compatible, SHOULD_CHECK_FOR_DATAFLOW_VIOLATIONS}; \
568+
}
569+
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE(false, ClassMethod)
570+
#undef ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE
571+
554572
// Trivial if trivial typed, otherwise must accept owned?
555573
#define ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(SHOULD_CHECK_FOR_DATAFLOW_VIOLATIONS, \
556574
INST) \
@@ -565,7 +583,6 @@ ACCEPTS_ANY_OWNERSHIP_INST(UncheckedOwnershipConversion)
565583
}
566584
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, SuperMethod)
567585
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, BridgeObjectToWord)
568-
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, ClassMethod)
569586
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, CopyBlock)
570587
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, DynamicMethod)
571588
ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(false, OpenExistentialBox)

test/SIL/ownership-verifier/use_verifier.sil

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ struct TupleContainingNonTrivialStruct {
5353
var opt: Optional<Builtin.NativeObject>
5454
}
5555

56-
class SuperKlass {}
56+
class SuperKlass {
57+
func d() {}
58+
}
5759
class SubKlass : SuperKlass {}
5860
class X {
5961
@objc func f() { }
@@ -342,6 +344,13 @@ bb0(%0 : @owned $@convention(block) () -> ()):
342344
return %9999 : $()
343345
}
344346

347+
sil @class_method_metatype_test : $@convention(thin) (@thick SuperKlass.Type) -> () {
348+
bb0(%0 : @trivial $@thick SuperKlass.Type):
349+
%1 = class_method %0 : $@thick SuperKlass.Type, #SuperKlass.d!1 : (SuperKlass) -> () -> (), $@convention(method) (@guaranteed SuperKlass) -> ()
350+
%9999 = tuple()
351+
return %9999 : $()
352+
}
353+
345354
//////////////////////
346355
// Terminator Tests //
347356
//////////////////////

0 commit comments

Comments
 (0)