Skip to content

Commit 5b44571

Browse files
committed
[DiagnoseUnreachable] Ignore dead_end destroys.
Such destroys mark the lifetime end of their operands along their availability boundary. They are currently inserted in this test case by the ClosureLifetimeFixup pass, but in the fullness of time they will be present for every value which is not explicitly destroyed (that's what complete OSSA lifetimes is mostly about). Currently, such destroys are diagnosed by DiagnoseUnreachable. Fix the diagnostic pass not to diagnose these valid instructions. rdar://137960229
1 parent d6e8eb2 commit 5b44571

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,14 @@ static bool simplifyBlocksWithCallsToNoReturn(SILBasicBlock &BB,
775775
if (isa<EndBorrowInst>(currInst))
776776
return false;
777777

778+
// destroy_value [dead_end] instructions are inserted at the availability
779+
// boundary by lifetime completion. Such instructions correctly mark the
780+
// lifetime boundary of the destroyed value and never arise from dead user
781+
// code.
782+
auto *dvi = dyn_cast<DestroyValueInst>(currInst);
783+
if (dvi && dvi->isDeadEnd())
784+
return false;
785+
778786
// If no-return instruction is not something we can point in code or
779787
// it's an explicit cast, skip it.
780788
if (!noReturnCall->getLoc().is<RegularLocation>() ||
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -c %s -verify
2+
3+
func testFatalError(_ message: @autoclosure () -> String = String()) -> Never {
4+
Swift.fatalError()
5+
}
6+
7+
func test() {
8+
testFatalError() // warning: Will never be executed
9+
}

0 commit comments

Comments
 (0)