Skip to content

Commit d535e3e

Browse files
committed
[ownership] Allow for the ownership verifier to be run in non-asserts builds if -sil-verify-all is set.
This is matching the behavior of the rest of the verifier. NOTE: Both early exit if said flag is not set, so this should not hit compile time in any way unless the flag is set (in which case someone is asking for more verification...). While I was here, I also noticed an ancillary bug where we were not checking if a value was from in a block that was in a SILGlobalVariable or a SILFunction. We already had a check that stopped this early when validating ownership of SILInstructions. I guess we have never had a situation where the verifier was given values to run on SILGlobalVariable blocks.
1 parent e2e114f commit d535e3e

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)