Skip to content

Commit 414d5ac

Browse files
authored
Merge pull request #16032 from aschwaighofer/fix_closure_lifetime_fixup
2 parents 130aba0 + b2d1554 commit 414d5ac

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ static SILBasicBlock *getOptionalDiamondSuccessor(SwitchEnumInst *SEI) {
5656
if (SuccNone == Succ)
5757
return Succ;
5858

59+
if (SuccNone == nullptr)
60+
return nullptr;
61+
5962
SuccNone = SuccNone->getSingleSuccessorBlock();
6063
if (SuccNone == Succ)
6164
return Succ;

test/SILOptimizer/closure_lifetime_fixup.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ public protocol P {
8282
public func testMaterializeForSet<T : P>(p: inout T) where T.Element == String {
8383
p[{Int($0)!}, {String($0)}] += 1
8484
}
85+
86+
public func dontCrash<In, Out>(test: Bool, body: @escaping ((In) -> Out, In) -> Out ) -> (In) -> Out {
87+
var result: ((In) -> Out)!
88+
result = { (x: In) in
89+
if test {
90+
return body(result, x)
91+
}
92+
let r = body(result, x)
93+
return r
94+
}
95+
return result
96+
}

0 commit comments

Comments
 (0)