Skip to content

Commit 28e33af

Browse files
authored
Merge pull request #78123 from meg-gupta/newflag
Add new flag -sil-ownership-verify-all
2 parents 2405db0 + 8b1ecb8 commit 28e33af

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ class SILOptions {
160160
/// Controls whether or not paranoid verification checks are run.
161161
bool VerifyAll = false;
162162

163+
/// Verify ownership after every pass.
164+
bool VerifyOwnershipAll = false;
165+
163166
/// If true, no SIL verification is done at all.
164167
bool VerifyNone = false;
165168

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@ def sil_verify_all : Flag<["-"], "sil-verify-all">,
941941

942942
def sil_verify_none : Flag<["-"], "sil-verify-none">,
943943
HelpText<"Completely disable SIL verification">;
944+
945+
def sil_ownership_verify_all : Flag<["-"], "sil-ownership-verify-all">,
946+
HelpText<"Verify ownership after each transform">;
944947

945948
def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
946949
HelpText<"Verify all SubstitutionMaps on construction">;

include/swift/SIL/SILFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,11 @@ class SILFunction
16591659
/// Verifies the lifetime of memory locations in the function.
16601660
void verifyMemoryLifetime(CalleeCache *calleeCache);
16611661

1662+
/// Verifies ownership of the function.
1663+
/// Since we don't have complete lifetimes everywhere, computes DeadEndBlocks
1664+
/// and calls verifyOwnership(DeadEndBlocks *deadEndBlocks)
1665+
void verifyOwnership() const;
1666+
16621667
/// Run the SIL ownership verifier to check that all values with ownership
16631668
/// have a linear lifetime. Regular OSSA invariants are checked separately in
16641669
/// normal SIL verification.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
28242824

28252825
Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
28262826
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
2827+
Opts.VerifyOwnershipAll |= Args.hasArg(OPT_sil_ownership_verify_all);
28272828
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
28282829
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
28292830
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,12 @@ void SILModule::verifyOwnership() const {
963963
}
964964
}
965965

966+
void SILFunction::verifyOwnership() const {
967+
auto deBlocks =
968+
std::make_unique<DeadEndBlocks>(const_cast<SILFunction *>(this));
969+
verifyOwnership(deBlocks.get());
970+
}
971+
966972
void SILFunction::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
967973
if (!getModule().getOptions().VerifySILOwnership)
968974
return;

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
760760
F->verify(getAnalysis<BasicCalleeAnalysis>()->getCalleeCache());
761761
verifyAnalyses(F);
762762
runSwiftFunctionVerification(F);
763+
} else if (getOptions().VerifyOwnershipAll &&
764+
(CurrentPassHasInvalidated || SILVerifyWithoutInvalidation)) {
765+
F->verifyOwnership();
763766
} else {
764767
if ((SILVerifyAfterPass.end() != std::find_if(SILVerifyAfterPass.begin(),
765768
SILVerifyAfterPass.end(),

0 commit comments

Comments
 (0)