Skip to content

Commit 8bbc706

Browse files
authored
Merge pull request swiftlang#35821 from eeckstein/fix-fso-5.4
[5.4] FunctionSignatureOptimization: prevent owned->guaranteed specialization in case of a dealloc_partial_ref
2 parents ddb635d + 1930cdf commit 8bbc706

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/SILOptimizer/Analysis/ARCAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ void ConsumedArgToEpilogueReleaseMatcher::collectMatchingReleases(
912912
// If we do not have a release_value or strong_release. We can continue
913913
if (!isa<ReleaseValueInst>(inst) && !isa<StrongReleaseInst>(inst)) {
914914
// We cannot match a final release if it is followed by a dealloc_ref.
915-
if (isa<DeallocRefInst>(inst))
915+
if (isa<DeallocRefInst>(inst) || isa<DeallocPartialRefInst>(inst))
916916
break;
917917

918918
// We do not know what this instruction is, do a simple check to make sure

test/SILOptimizer/functionsigopts.sil

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,48 @@ bb0(%0 : $Builtin.NativeObject, %1 : $Int):
945945
return %r1 : $Int
946946
}
947947

948+
//=======================================================================
949+
// dont convert @owned => @guaranteed when there is a dealloc_partial_ref
950+
951+
sil @test_dealloc_partial_ref_callee : $@convention(thin) () -> ((), @error Error)
952+
953+
// CHECK-LABEL: sil hidden @test_dealloc_partial_ref : $@convention(thin) (@owned foo) -> (@owned foo, @error Error) {
954+
// CHECK-NOT: @guaranteed
955+
// CHECK: function_ref @test_dealloc_partial_ref_callee
956+
// CHECK-NOT: @guaranteed
957+
958+
sil hidden @test_dealloc_partial_ref : $@convention(thin) (@owned foo) -> (@owned foo, @error Error) {
959+
bb0(%1 : $foo):
960+
strong_retain %1 : $foo
961+
%f = function_ref @test_dealloc_partial_ref_callee : $@convention(thin) () -> ((), @error Error)
962+
try_apply %f() : $@convention(thin) () -> ((), @error Error), normal bb1, error bb2
963+
964+
bb1(%27 : $()):
965+
strong_release %1 : $foo
966+
return %1 : $foo
967+
968+
bb2(%157 : $Error):
969+
strong_release %1 : $foo
970+
%mt = metatype $@thick foo.Type
971+
dealloc_partial_ref %1 : $foo, %mt : $@thick foo.Type
972+
throw %157 : $Error
973+
}
974+
975+
sil @test_dealloc_partial_ref_caller : $@convention(thin) () -> (@owned foo, @error Error) {
976+
bb0:
977+
%2 = alloc_ref $foo
978+
%3 = function_ref @test_dealloc_partial_ref : $@convention(thin) (@owned foo) -> (@owned foo, @error Error)
979+
try_apply %3(%2) : $@convention(thin) (@owned foo) -> (@owned foo, @error Error), normal bb1, error bb2
980+
981+
bb1(%5 : $foo):
982+
return %5 : $foo
983+
984+
bb2(%7 : $Error):
985+
throw %7 : $Error
986+
}
987+
988+
// CHECK: } // end sil function 'test_dealloc_partial_ref_caller'
989+
948990
//======================
949991
// @owned => @guaranteed
950992

0 commit comments

Comments
 (0)