Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ownership] Allow for the ownership verifier to be run in non-asserts… #27499

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ class SILValue {
NumLowBitsAvailable
};

/// If this SILValue is a result of an instruction, return its
/// defining instruction. Returns nullptr otherwise.
SILInstruction *getDefiningInstruction() {
return Value->getDefiningInstruction();
}

/// If this SILValue is a result of an instruction, return its
/// defining instruction. Returns nullptr otherwise.
const SILInstruction *getDefiningInstruction() const {
return Value->getDefiningInstruction();
}

/// Returns the ValueOwnershipKind that describes this SILValue's ownership
/// semantics if the SILValue has ownership semantics. Returns is a value
/// without any Ownership Semantics.
Expand Down
26 changes: 22 additions & 4 deletions lib/SIL/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,19 @@ bool SILValueOwnershipChecker::checkUses() {
//===----------------------------------------------------------------------===//

void SILInstruction::verifyOperandOwnership() const {
#ifndef NDEBUG
if (DisableOwnershipVerification)
return;

if (isStaticInitializerInst())
return;

#ifdef NDEBUG
// When compiling without asserts enabled, only verify ownership if
// -sil-verify-all is set.
if (!getModule().getOptions().VerifyAll)
return;
#endif

// If SILOwnership is not enabled, do not perform verification.
if (!getModule().getOptions().VerifySILOwnership)
return;
Expand Down Expand Up @@ -631,14 +637,27 @@ void SILInstruction::verifyOperandOwnership() const {
"At this point, we are expected to assert");
llvm_unreachable("triggering standard assertion failure routine");
}
#endif
}

void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
#ifndef NDEBUG
if (DisableOwnershipVerification)
return;

#ifdef NDEBUG
// When compiling without asserts enabled, only verify ownership if
// -sil-verify-all is set.
if (!getModule().getOptions().VerifyAll)
return;
#endif

// Make sure that we are not a value of an instruction in a SILGlobalVariable
// block.
if (auto *definingInst = getDefiningInstruction()) {
if (definingInst->isStaticInitializerInst()) {
return;
}
}

// Since we do not have SILUndef, we now know that getFunction() should return
// a real function. Assert in case this assumption is no longer true.
SILFunction *f = (*this)->getFunction();
Expand Down Expand Up @@ -667,5 +686,4 @@ void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
liveBlocks)
.check();
}
#endif
}