Skip to content

SILCombine: fix wrong placement of a strong_release of a dead closure argument which caused a memory leak #21391

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 1 commit into from
Dec 18, 2018
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
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Analysis/ARCAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ bool swift::getFinalReleasesForValue(SILValue V, ReleaseTracker &Tracker) {

// Try to speed up the trivial case of single release/dealloc.
if (isa<StrongReleaseInst>(User) || isa<DeallocBoxInst>(User) ||
isa<DestroyValueInst>(User)) {
isa<DestroyValueInst>(User) || isa<ReleaseValueInst>(User)) {
if (!seenRelease)
OneRelease = User;
else
Expand Down
24 changes: 24 additions & 0 deletions test/SILOptimizer/sil_combine.sil
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ bb0(%0 : $Builtin.RawPointer):
return %2 : $Builtin.RawPointer
}

sil @test_closure : $@convention(thin) (@guaranteed C) -> ()

// CHECK-LABEL: sil @dead_closure_elimination
// CHECK: bb0(%0 : $C):
// CHECK-NEXT: cond_br
// CHECK-NOT: strong_release
// CHECK: bb2:
// CHECK-NEXT: strong_release %0
// CHECK return
sil @dead_closure_elimination : $@convention(thin) (@owned C) -> () {
bb0(%0 : $C):
%1 = function_ref @test_closure : $@convention(thin) (@guaranteed C) -> ()
%2 = partial_apply [callee_guaranteed] %1(%0) : $@convention(thin) (@guaranteed C) -> ()
cond_br undef, bb1, bb2
bb1:
strong_retain %2 : $@callee_guaranteed () -> ()
strong_release %2 : $@callee_guaranteed () -> ()
br bb2
bb2:
release_value %2 : $@callee_guaranteed () -> ()
%5 = tuple()
return %5 : $()
}

////////////////////////////////////////////
// Load Proj To GEP Load Canonicalization //
////////////////////////////////////////////
Expand Down