Skip to content

Commit 9fbbab8

Browse files
committed
[ClosureLifetimeFixup] Cleanups get CleanupLocs.
1 parent bf84d8d commit 9fbbab8

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ void swift::insertDestroyOfCapturedArguments(
14621462
ApplySite site(pai);
14631463
SILFunctionConventions calleeConv(site.getSubstCalleeType(),
14641464
pai->getModule());
1465-
auto loc = RegularLocation::getAutoGeneratedLocation();
1465+
auto loc = CleanupLocation(RegularLocation::getAutoGeneratedLocation());
14661466
for (auto &arg : pai->getArgumentOperands()) {
14671467
if (!shouldInsertDestroy(arg.get()))
14681468
continue;
@@ -1480,7 +1480,7 @@ void swift::insertDeallocOfCapturedArguments(
14801480
ApplySite site(pai);
14811481
SILFunctionConventions calleeConv(site.getSubstCalleeType(),
14821482
pai->getModule());
1483-
auto loc = RegularLocation::getAutoGeneratedLocation();
1483+
auto loc = CleanupLocation(RegularLocation::getAutoGeneratedLocation());
14841484
for (auto &arg : pai->getArgumentOperands()) {
14851485
unsigned calleeArgumentIndex = site.getCalleeArgIndex(arg);
14861486
assert(calleeArgumentIndex >= calleeConv.getSILArgIndexOfFirstParam());
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all -closure-lifetime-fixup -emit-verbose-sil %s | %FileCheck %s
2+
3+
import Builtin
4+
import Swift
5+
import SwiftShims
6+
7+
8+
sil_scope 1 { loc "closure-lifetime-fixup-debuginfo.sil":12:34 parent @destroy_and_dealloc_of_capture_are_cleanups : $@convention(method) <Self where Self : Indexable> (@in Self) -> () }
9+
sil_scope 2 { loc "closure-lifetime-fixup-debuginfo.sil":12:34 parent 1 }
10+
11+
protocol Indexable {
12+
associatedtype Index
13+
}
14+
15+
// Verify that the destroy_addr and dealloc_stack that are created for captured
16+
// closure arguments are marked as cleanups.
17+
// CHECK-LABEL: sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : {{.*}} {
18+
// CHECK: [[CAPTURED_ADDR:%[^,]+]] = alloc_stack $Self
19+
// CHECK: try_apply {{.*}}, normal [[SUCCESS:bb[0-9]+]]
20+
// CHECK: [[SUCCESS]]
21+
// CHECK: destroy_addr [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen
22+
// ^^^^^^^
23+
// CHECK: dealloc_stack [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen
24+
// ^^^^^^^
25+
// CHECK-LABEL: } // end sil function 'destroy_and_dealloc_of_capture_are_cleanups'
26+
sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : $@convention(method) <Self where Self : Indexable> (@in Self) -> () {
27+
bb0(%self : $*Self):
28+
%copy = alloc_stack $Self, scope 1
29+
copy_addr %self to [init] %copy : $*Self, scope 2
30+
%closure = partial_apply [callee_guaranteed] undef<Self>(%copy) : $@convention(thin) <Tee where Tee : Indexable> (@in_guaranteed Tee) -> (@out Tee.Index, @error any Error), scope 2
31+
%converted = convert_function %closure : $@callee_guaranteed () -> (@out Self.Index, @error any Error) to $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2
32+
%noescape = convert_escape_to_noescape [not_guaranteed] %converted : $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index> to $@noescape @callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2
33+
try_apply undef<Self.Index>(%noescape) : $@convention(thin) <Tee> (@noescape @callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Tee>) -> (@error any Error), normal bb1, error bb2, scope 2
34+
bb1(%result : $()):
35+
destroy_value %converted : $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2
36+
destroy_addr %self : $*Self, scope 2
37+
%retval = tuple (), scope 2
38+
dealloc_stack %copy : $*Self, scope 2
39+
return %retval : $(), scope 2
40+
41+
bb2(%83 : @owned $any Error):
42+
unreachable , scope 2
43+
}

0 commit comments

Comments
 (0)