Skip to content

Commit 0c7b94e

Browse files
committed
ClosureLifetimeFixup: Don't insert dealloc_stack at unreachable
1 parent b6f9129 commit 0c7b94e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ static bool tryRewriteToPartialApplyStack(
297297
// Insert destroys of arguments after the apply and the dealloc_stack.
298298
if (auto *Apply = dyn_cast<ApplyInst>(singleApplyUser)) {
299299
auto InsertPt = std::next(SILBasicBlock::iterator(Apply));
300+
// Don't insert dealloc_stacks at unreachable.
301+
if (isa<UnreachableInst>(*InsertPt))
302+
return true;
300303
SILBuilderWithScope B3(InsertPt);
301304
B3.createDeallocStack(loc, newPA);
302305
insertDestroyOfCapturedArguments(newPA, B3);
@@ -684,6 +687,7 @@ class ClosureLifetimeFixup : public SILFunctionTransform {
684687

685688
bool checkStackNesting = false;
686689
bool modifiedCFG = false;
690+
687691
if (fixupClosureLifetimes(*getFunction(), checkStackNesting)) {
688692
if (checkStackNesting){
689693
StackNesting SN;

test/SILOptimizer/closure_lifetime_fixup.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ public func dontCrash<In, Out>(test: Bool, body: @escaping ((In) -> Out, In) ->
9999
public func to_stack_of_convert_function(p: UnsafeMutableRawPointer?) {
100100
_ = p.map(String.init(describing:))
101101
}
102+
103+
104+
public func no_dealloc_stack_before_unreachable(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line) -> Never {
105+
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
106+
}

0 commit comments

Comments
 (0)