Skip to content

Commit 3542af9

Browse files
authored
Merge pull request #78109 from meg-gupta/ossablocklist1
Allow disabling ownership verification via blocklist
2 parents f1f3604 + bb68264 commit 3542af9

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

include/swift/Basic/BlockListAction.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ BLOCKLIST_ACTION(ShouldUseBinaryModule)
2323
BLOCKLIST_ACTION(ShouldUseTextualModule)
2424
BLOCKLIST_ACTION(DowngradeInterfaceVerificationFailure)
2525
BLOCKLIST_ACTION(ShouldUseLayoutStringValueWitnesses)
26+
BLOCKLIST_ACTION(ShouldDisableOwnershipVerification)
2627

2728
#undef BLOCKLIST_ACTION

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,24 @@ bool SILValueOwnershipChecker::checkUses() {
802802
return true;
803803
}
804804

805+
bool disableOwnershipVerification(const SILModule &mod) {
806+
if (DisableOwnershipVerification)
807+
return true;
808+
if (mod.getASTContext().blockListConfig.hasBlockListAction(
809+
mod.getSwiftModule()->getRealName().str(),
810+
BlockListKeyKind::ModuleName,
811+
BlockListAction::ShouldDisableOwnershipVerification)) {
812+
return true;
813+
}
814+
return false;
815+
}
816+
805817
//===----------------------------------------------------------------------===//
806818
// Top Level Entrypoints
807819
//===----------------------------------------------------------------------===//
808820

809821
void SILInstruction::verifyOperandOwnership(
810822
SILModuleConventions *silConv) const {
811-
if (DisableOwnershipVerification)
812-
return;
813-
814823
if (isStaticInitializerInst())
815824
return;
816825

@@ -831,11 +840,13 @@ void SILInstruction::verifyOperandOwnership(
831840
!getFunction()->shouldVerifyOwnership())
832841
return;
833842

843+
if (disableOwnershipVerification(getModule()))
844+
return;
845+
834846
// If we are testing the verifier, bail so we only print errors once when
835847
// performing a full verification, instead of additionally in the SILBuilder.
836848
if (IsSILOwnershipVerifierTestingEnabled)
837849
return;
838-
839850
// If this is a terminator instruction, do not verify in SILBuilder. This is
840851
// because when building a new function, one must create the destination block
841852
// first which is an unnatural pattern and pretty brittle.
@@ -903,9 +914,6 @@ verifySILValueHelper(const SILFunction *f, SILValue value,
903914
}
904915

905916
void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
906-
if (DisableOwnershipVerification)
907-
return;
908-
909917
// Do not validate SILUndef values.
910918
if (isa<SILUndef>(*this))
911919
return;
@@ -918,18 +926,21 @@ void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
918926
}
919927
}
920928

929+
// Since we do not have SILUndef, we now know that getFunction() should return
930+
// a real function. Assert in case this assumption is no longer true.
931+
auto *f = (*this)->getFunction();
932+
assert(f && "Instructions and arguments should have a function");
933+
934+
if (disableOwnershipVerification(f->getModule()))
935+
return;
936+
921937
// If we are testing the verifier, bail so we only print errors once when
922938
// performing a full verification a function at a time by the
923939
// OwnershipVerifierStateDumper pass, instead of additionally in the
924940
// SILBuilder and in the actual SIL verifier that may be run by sil-opt.
925941
if (IsSILOwnershipVerifierTestingEnabled)
926942
return;
927943

928-
// Since we do not have SILUndef, we now know that getFunction() should return
929-
// a real function. Assert in case this assumption is no longer true.
930-
auto *f = (*this)->getFunction();
931-
assert(f && "Instructions and arguments should have a function");
932-
933944
using BehaviorKind = LinearLifetimeChecker::ErrorBehaviorKind;
934945
LinearLifetimeChecker::ErrorBuilder errorBuilder(
935946
*f, BehaviorKind::PrintMessageAndAssert);
@@ -939,7 +950,7 @@ void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
939950
}
940951

941952
void SILModule::verifyOwnership() const {
942-
if (DisableOwnershipVerification)
953+
if (disableOwnershipVerification(*this))
943954
return;
944955

945956
for (const SILFunction &function : *this) {
@@ -953,8 +964,6 @@ void SILModule::verifyOwnership() const {
953964
}
954965

955966
void SILFunction::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
956-
if (DisableOwnershipVerification)
957-
return;
958967
if (!getModule().getOptions().VerifySILOwnership)
959968
return;
960969

@@ -963,6 +972,9 @@ void SILFunction::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
963972
if (!hasOwnership() || !shouldVerifyOwnership())
964973
return;
965974

975+
if (disableOwnershipVerification(getModule()))
976+
return;
977+
966978
using BehaviorKind = LinearLifetimeChecker::ErrorBehaviorKind;
967979
unsigned errorCounter = 0;
968980
std::optional<LinearLifetimeChecker::ErrorBuilder> errorBuilder;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: echo "---" > %t/blocklist.yml
4+
// RUN: echo "ShouldDisableOwnershipVerification:" >> %t/blocklist.yml
5+
// RUN: echo " ModuleName:" >> %t/blocklist.yml
6+
// RUN: echo " - Foo" >> %t/blocklist.yml
7+
8+
// RUN: %target-swift-frontend -emit-sil -module-name Foo -blocklist-file %t/blocklist.yml %s | %FileCheck %s
9+
10+
class Klass {}
11+
12+
// CHECK-LABEL: sil @invalid_destroy
13+
// CHECK: strong_release
14+
sil [ossa] @invalid_destroy : $@convention(thin) (@guaranteed Klass) -> () {
15+
bb0(%0 : @guaranteed $Klass):
16+
destroy_value %0 : $Klass
17+
%t = tuple ()
18+
return %t : $()
19+
}
20+

0 commit comments

Comments
 (0)