Skip to content

Commit c197ca1

Browse files
committed
[OSSACompleteLifetime] Promote assertion.
Use llvm::report_fatal_error instead. Also, add logging to clarify that reaching this point is a bug in the incoming SIL.
1 parent 4edddf2 commit c197ca1

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,34 @@ 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+
llvm::errs() << "Invalid SIL provided to OSSALifetimeCompletion?! {{\n";
338+
llvm::errs() << "OSSALifetimeCompletion is visiting the availability "
339+
"boundary of ";
340+
value->print(llvm::errs());
341+
llvm::errs()
342+
<< "When walking forward from the def to the availability boundary "
343+
"a non-dead-end successor-less block was encountered: bb"
344+
<< block->getDebugID()
345+
<< "\nIts terminator must be an unreachable but is actually "
346+
"instead "
347+
<< *block->getTerminator()
348+
<< "The walk stops at consumes, so reaching such a block means the "
349+
"value was leaked. The function with the leak is as follows:\n";
350+
block->getFunction()->print(llvm::errs());
351+
llvm::errs()
352+
<< "Invalid SIL provided to OSSALifetimeCompletion?! }}\n"
353+
<< "Something that ran before OSSALifetimeCompletion (the current "
354+
"pass, an earlier pass, SILGen) has introduced a leak of this "
355+
"value.\n"
356+
<< "Please rerun the crashing swift-frontend command with the "
357+
"following flags added and file a bug with the output:\n"
358+
<< "-sil-ownership-verify-all -Xllvm '-sil-print-function="
359+
<< block->getFunction()->getName()
360+
<< "' -Xllvm -sil-print-types -Xllvm -sil-print-module-on-error\n";
361+
llvm::report_fatal_error("Invalid lifetime of value whose availability "
362+
"boundary is being visited.");
363+
}
337364
}
338365
for (auto *successor : block->getSuccessorBlocks()) {
339366
regionWorklist.pushIfNotVisited(successor);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: not --crash %target-sil-opt -sil-print-types \
3+
// RUN: -test-runner \
4+
// RUN: %s \
5+
// RUN: -sil-disable-input-verify \
6+
// RUN: -o /dev/null \
7+
// RUN: 2>&1 | tee %t/out
8+
// RUN: %FileCheck %s < %t/out
9+
10+
11+
12+
class C {}
13+
14+
// CHECK: Invalid SIL provided to OSSALifetimeCompletion?!
15+
// CHECK: OSSALifetimeCompletion is visiting the availability boundary of %0 = argument of bb0 : $C
16+
// CHECK: When walking forward from the def to the availability boundary a non-dead-end successor-less block was encountered: bb0
17+
// CHECK: Its terminator must be an unreachable but is actually instead return undef : $() // id: %1
18+
// CHECK: The walk stops at consumes, so reaching such a block means the value was leaked. The function with the leak is as follows:
19+
// CHECK: sil [ossa] @leak_c : $@convention(thin) (@owned C) -> () {
20+
// CHECK: bb0(%0 : @owned $C):
21+
// CHECK: return undef : $()
22+
// CHECK: } // end sil function 'leak_c'
23+
// CHECK: Invalid SIL provided to OSSALifetimeCompletion?!
24+
// CHECK: Something that ran before OSSALifetimeCompletion (the current pass, an earlier pass, SILGen) has introduced a leak of this value.
25+
// CHECK: Please rerun the crashing swift-frontend command with the following flags added and file a bug with the output:
26+
// CHECK: -sil-ownership-verify-all -Xllvm '-sil-print-function=leak_c' -Xllvm -sil-print-types -Xllvm -sil-print-module-on-error
27+
// CHECK: Invalid lifetime of value whose availability boundary is being visited.
28+
sil [ossa] @leak_c : $@convention(thin) (@owned C) -> () {
29+
entry(%c : @owned $C):
30+
specify_test "ossa_lifetime_completion @argument availability"
31+
return undef : $()
32+
}

0 commit comments

Comments
 (0)