Skip to content

[DiagnoseUnreachable] Ignore dead_end destroys. #77044

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

Merged
merged 1 commit into from
Oct 16, 2024
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
8 changes: 8 additions & 0 deletions lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,14 @@ static bool simplifyBlocksWithCallsToNoReturn(SILBasicBlock &BB,
if (isa<EndBorrowInst>(currInst))
return false;

// destroy_value [dead_end] instructions are inserted at the availability
// boundary by lifetime completion. Such instructions correctly mark the
// lifetime boundary of the destroyed value and never arise from dead user
// code.
auto *dvi = dyn_cast<DestroyValueInst>(currInst);
if (dvi && dvi->isDeadEnd())
return false;

// If no-return instruction is not something we can point in code or
// it's an explicit cast, skip it.
if (!noReturnCall->getLoc().is<RegularLocation>() ||
Expand Down
9 changes: 9 additions & 0 deletions validation-test/SILOptimizer/rdar137960229.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -c %s -verify

func testFatalError(_ message: @autoclosure () -> String = String()) -> Never {
Swift.fatalError()
}

func test() {
testFatalError()
}