Skip to content

[ClosureLifetimeFixup] Cleanups get CleanupLocs. #62533

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
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
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Utils/InstOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ void swift::insertDestroyOfCapturedArguments(
ApplySite site(pai);
SILFunctionConventions calleeConv(site.getSubstCalleeType(),
pai->getModule());
auto loc = RegularLocation::getAutoGeneratedLocation();
auto loc = CleanupLocation(RegularLocation::getAutoGeneratedLocation());
for (auto &arg : pai->getArgumentOperands()) {
if (!shouldInsertDestroy(arg.get()))
continue;
Expand All @@ -1480,7 +1480,7 @@ void swift::insertDeallocOfCapturedArguments(
ApplySite site(pai);
SILFunctionConventions calleeConv(site.getSubstCalleeType(),
pai->getModule());
auto loc = RegularLocation::getAutoGeneratedLocation();
auto loc = CleanupLocation(RegularLocation::getAutoGeneratedLocation());
for (auto &arg : pai->getArgumentOperands()) {
unsigned calleeArgumentIndex = site.getCalleeArgIndex(arg);
assert(calleeArgumentIndex >= calleeConv.getSILArgIndexOfFirstParam());
Expand Down
43 changes: 43 additions & 0 deletions test/SILOptimizer/closure-lifetime-fixup-debuginfo.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// RUN: %target-sil-opt -enable-sil-verify-all -closure-lifetime-fixup -emit-verbose-sil %s | %FileCheck %s

import Builtin
import Swift
import SwiftShims


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) -> () }
sil_scope 2 { loc "closure-lifetime-fixup-debuginfo.sil":12:34 parent 1 }

protocol Indexable {
associatedtype Index
}

// Verify that the destroy_addr and dealloc_stack that are created for captured
// closure arguments are marked as cleanups.
// CHECK-LABEL: sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : {{.*}} {
// CHECK: [[CAPTURED_ADDR:%[^,]+]] = alloc_stack $Self
// CHECK: try_apply {{.*}}, normal [[SUCCESS:bb[0-9]+]]
// CHECK: [[SUCCESS]]
// CHECK: destroy_addr [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen
// ^^^^^^^
// CHECK: dealloc_stack [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen
// ^^^^^^^
// CHECK-LABEL: } // end sil function 'destroy_and_dealloc_of_capture_are_cleanups'
sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : $@convention(method) <Self where Self : Indexable> (@in Self) -> () {
bb0(%self : $*Self):
%copy = alloc_stack $Self, scope 1
copy_addr %self to [init] %copy : $*Self, scope 2
%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
%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
%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
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
bb1(%result : $()):
destroy_value %converted : $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2
destroy_addr %self : $*Self, scope 2
%retval = tuple (), scope 2
dealloc_stack %copy : $*Self, scope 2
return %retval : $(), scope 2

bb2(%83 : @owned $any Error):
unreachable , scope 2
}