Skip to content

Commit 96cd2e1

Browse files
authored
Merge pull request #85987 from meg-gupta/undefcapture
Tolerate undef closure captures in ClosureLifetimeFixup
2 parents 74c8fcf + f30b584 commit 96cd2e1

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,9 @@ void swift::insertDeallocOfCapturedArguments(
15531553
if (!argValue) {
15541554
continue;
15551555
}
1556+
if (isa<SILUndef>(argValue)) {
1557+
continue;
1558+
}
15561559

15571560
SmallVector<SILBasicBlock *, 4> boundary;
15581561
auto *asi = cast<AllocStackInst>(argValue);

test/SILOptimizer/closure-lifetime-fixup.sil

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,18 @@ bb1:
164164
return %86 : $()
165165
}
166166

167-
sil [ossa] @closureImpl : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> Bool
167+
sil [ossa] @closureImpl1 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> Bool
168+
sil [ossa] @closureImpl2 : $@convention(thin) (@guaranteed Klass, @in_guaranteed Klass) -> Bool
168169
sil [ossa] @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> Bool) -> ()
169170

170171
// Don't crash.
171-
// CHECK-LABEL: sil hidden [ossa] @testUndefined
172+
// CHECK-LABEL: sil hidden [ossa] @testUndefined1
172173
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [on_stack]
173174
// CHECK: destroy_value [[PA]] : $@noescape @callee_guaranteed () -> Bool
174175
// CHECK: destroy_value
175-
sil hidden [ossa] @testUndefined : $@convention(method) (@guaranteed Klass, @guaranteed Klass) -> () {
176+
sil hidden [ossa] @testUndefined1 : $@convention(method) (@guaranteed Klass, @guaranteed Klass) -> () {
176177
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
177-
%4 = function_ref @closureImpl : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> Bool
178+
%4 = function_ref @closureImpl1 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> Bool
178179
%5 = copy_value %1 : $Klass
179180
%6 = partial_apply [callee_guaranteed] %4(%5, undef) : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> Bool
180181
%7 = convert_escape_to_noescape [not_guaranteed] %6 : $@callee_guaranteed () -> Bool to $@noescape @callee_guaranteed () -> Bool
@@ -186,6 +187,23 @@ bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
186187
return %42 : $()
187188
}
188189

190+
// Don't crash on undef in insertDeallocOfCapturedArguments
191+
// CHECK-LABEL: sil hidden [ossa] @testUndefined2 :
192+
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [on_stack]
193+
sil hidden [ossa] @testUndefined2 : $@convention(method) (@guaranteed Klass, @in_guaranteed Klass) -> () {
194+
bb0(%0 : @guaranteed $Klass, %1 : $*Klass):
195+
%4 = function_ref @closureImpl2 : $@convention(thin) (@guaranteed Klass, @in_guaranteed Klass) -> Bool
196+
%5 = copy_value %0 : $Klass
197+
%6 = partial_apply [callee_guaranteed] %4(%5, undef) : $@convention(thin) (@guaranteed Klass, @in_guaranteed Klass) -> Bool
198+
%7 = convert_escape_to_noescape [not_guaranteed] %6 : $@callee_guaranteed () -> Bool to $@noescape @callee_guaranteed () -> Bool
199+
%21 = function_ref @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> Bool) -> ()
200+
%22 = apply %21(%7) : $@convention(thin) (@noescape @callee_guaranteed () -> Bool) -> ()
201+
destroy_value %7 : $@noescape @callee_guaranteed () -> Bool
202+
destroy_value %6 : $@callee_guaranteed () -> Bool
203+
%42 = tuple ()
204+
return %42 : $()
205+
}
206+
189207
sil @simpleClosure : $@convention(thin) () -> ()
190208

191209
// Don't crash.

0 commit comments

Comments
 (0)