Skip to content

Commit 6d789e3

Browse files
authored
Merge pull request #27499 from gottesmm/pr-dc6371871f1797246355f4fc6795f1d0116e360a
[ownership] Allow for the ownership verifier to be run in non-asserts…
2 parents 03edea3 + d535e3e commit 6d789e3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

include/swift/SIL/SILValue.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ class SILValue {
387387
NumLowBitsAvailable
388388
};
389389

390+
/// If this SILValue is a result of an instruction, return its
391+
/// defining instruction. Returns nullptr otherwise.
392+
SILInstruction *getDefiningInstruction() {
393+
return Value->getDefiningInstruction();
394+
}
395+
396+
/// If this SILValue is a result of an instruction, return its
397+
/// defining instruction. Returns nullptr otherwise.
398+
const SILInstruction *getDefiningInstruction() const {
399+
return Value->getDefiningInstruction();
400+
}
401+
390402
/// Returns the ValueOwnershipKind that describes this SILValue's ownership
391403
/// semantics if the SILValue has ownership semantics. Returns is a value
392404
/// without any Ownership Semantics.

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,19 @@ bool SILValueOwnershipChecker::checkUses() {
569569
//===----------------------------------------------------------------------===//
570570

571571
void SILInstruction::verifyOperandOwnership() const {
572-
#ifndef NDEBUG
573572
if (DisableOwnershipVerification)
574573
return;
575574

576575
if (isStaticInitializerInst())
577576
return;
578577

578+
#ifdef NDEBUG
579+
// When compiling without asserts enabled, only verify ownership if
580+
// -sil-verify-all is set.
581+
if (!getModule().getOptions().VerifyAll)
582+
return;
583+
#endif
584+
579585
// If SILOwnership is not enabled, do not perform verification.
580586
if (!getModule().getOptions().VerifySILOwnership)
581587
return;
@@ -631,14 +637,27 @@ void SILInstruction::verifyOperandOwnership() const {
631637
"At this point, we are expected to assert");
632638
llvm_unreachable("triggering standard assertion failure routine");
633639
}
634-
#endif
635640
}
636641

637642
void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
638-
#ifndef NDEBUG
639643
if (DisableOwnershipVerification)
640644
return;
641645

646+
#ifdef NDEBUG
647+
// When compiling without asserts enabled, only verify ownership if
648+
// -sil-verify-all is set.
649+
if (!getModule().getOptions().VerifyAll)
650+
return;
651+
#endif
652+
653+
// Make sure that we are not a value of an instruction in a SILGlobalVariable
654+
// block.
655+
if (auto *definingInst = getDefiningInstruction()) {
656+
if (definingInst->isStaticInitializerInst()) {
657+
return;
658+
}
659+
}
660+
642661
// Since we do not have SILUndef, we now know that getFunction() should return
643662
// a real function. Assert in case this assumption is no longer true.
644663
SILFunction *f = (*this)->getFunction();
@@ -667,5 +686,4 @@ void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
667686
liveBlocks)
668687
.check();
669688
}
670-
#endif
671689
}

0 commit comments

Comments
 (0)