@@ -333,7 +333,40 @@ void AvailabilityBoundaryVisitor::computeRegion(
333333 // Thus finding a value available at the end of such a block means that
334334 // the block does _not_ must not exits the function normally; in other
335335 // words its terminator must be an UnreachableInst.
336- assert (isa<UnreachableInst>(block->getTerminator ()));
336+ if (!isa<UnreachableInst>(block->getTerminator ()) &&
337+ block->getFunction ()
338+ ->getModule ()
339+ .getASTContext ()
340+ .SILOpts .VerifySILOwnership ) {
341+ llvm::errs () << " Invalid SIL provided to OSSALifetimeCompletion?! {{\n " ;
342+ llvm::errs () << " OSSALifetimeCompletion is visiting the availability "
343+ " boundary of " ;
344+ value->print (llvm::errs ());
345+ llvm::errs ()
346+ << " When walking forward from the def to the availability boundary "
347+ " a non-dead-end successor-less block was encountered: bb"
348+ << block->getDebugID ()
349+ << " \n Its terminator must be an unreachable but is actually "
350+ " instead "
351+ << *block->getTerminator ()
352+ << " The walk stops at consumes, so reaching such a block means the "
353+ " value was leaked. The function with the leak is as follows:\n " ;
354+ block->getFunction ()->print (llvm::errs ());
355+ llvm::errs ()
356+ << " Invalid SIL provided to OSSALifetimeCompletion?! }}\n "
357+ << " Something that ran before OSSALifetimeCompletion (the current "
358+ " pass, an earlier pass, SILGen) has introduced a leak of this "
359+ " value.\n "
360+ << " Please rerun the crashing swift-frontend command with the "
361+ " following flags added and file a bug with the output:\n "
362+ << " -sil-ownership-verify-all -Xllvm '-sil-print-function="
363+ << block->getFunction ()->getName ()
364+ << " ' -Xllvm -sil-print-types -Xllvm -sil-print-module-on-error\n " ;
365+ llvm::errs () << " Use the -disable-sil-ownership-verifier to disable "
366+ " this check.\n " ;
367+ llvm::report_fatal_error (" Invalid lifetime of value whose availability "
368+ " boundary is being visited." );
369+ }
337370 }
338371 for (auto *successor : block->getSuccessorBlocks ()) {
339372 regionWorklist.pushIfNotVisited (successor);
@@ -403,7 +436,11 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
403436 continue ;
404437 }
405438 assert (hasUnavailableSuccessor () ||
406- isa<UnreachableInst>(block->getTerminator ()));
439+ isa<UnreachableInst>(block->getTerminator ()) ||
440+ !block->getFunction ()
441+ ->getModule ()
442+ .getASTContext ()
443+ .SILOpts .VerifySILOwnership );
407444 visit (block->getTerminator (),
408445 OSSALifetimeCompletion::LifetimeEnd::Boundary);
409446 }
0 commit comments