Skip to content

Commit 0e5ed97

Browse files
authored
Merge pull request #14833 from gottesmm/swift-5.0-branchrdar37820485
[arc] An apply of a callee_guaranteed thick function is a "guaranteed…
2 parents 95c63ee + 2f40e8e commit 0e5ed97

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/SILOptimizer/Analysis/ARCAnalysis.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,24 @@ mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
441441

442442
FullApplySite FAS(User);
443443

444-
// Ok, we have a full apply site. If the apply has no arguments, we don't need
445-
// to worry about any guaranteed parameters.
444+
// Ok, we have a full apply site. Check if the callee is callee_guaranteed. In
445+
// such a case, if we can not prove no alias, we need to be conservative and
446+
// return true.
447+
CanSILFunctionType FType = FAS.getSubstCalleeType();
448+
if (FType->isCalleeGuaranteed() && !AA->isNoAlias(FAS.getCallee(), Ptr)) {
449+
return true;
450+
}
451+
452+
// Ok, we have a full apply site and our callee is a normal use. Thus if the
453+
// apply does not have any normal arguments, we don't need to worry about any
454+
// guaranteed parameters and return early.
446455
if (!FAS.getNumArguments())
447456
return false;
448457

449458
// Ok, we have an apply site with arguments. Look at the function type and
450459
// iterate through the function parameters. If any of the parameters are
451460
// guaranteed, attempt to prove that the passed in parameter cannot alias
452461
// Ptr. If we fail, return true.
453-
CanSILFunctionType FType = FAS.getSubstCalleeType();
454462
auto Params = FType->getParameters();
455463
for (unsigned i : indices(Params)) {
456464
if (!Params[i].isGuaranteed())

test/SILOptimizer/arcsequenceopts.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,3 +2146,20 @@ bb0(%0 : $*Builtin.NativeObject):
21462146
strong_release %1 : $Builtin.NativeObject
21472147
return undef : $()
21482148
}
2149+
2150+
// Make sure that we treat applications of callee_guaranteed functions as a
2151+
// guaranteed use of the function object.
2152+
//
2153+
// CHECK-LABEL: sil @test_callee_guaranteed_is_treated_as_guaranteed : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
2154+
// CHECK: strong_retain
2155+
// CHECK: apply
2156+
// CHECK: strong_release
2157+
// CHECK: } // end sil function 'test_callee_guaranteed_is_treated_as_guaranteed'
2158+
sil @test_callee_guaranteed_is_treated_as_guaranteed : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
2159+
bb0(%0 : $@callee_guaranteed () -> ()):
2160+
strong_retain %0 : $@callee_guaranteed () -> ()
2161+
apply %0() : $@callee_guaranteed () -> ()
2162+
strong_release %0 : $@callee_guaranteed () -> ()
2163+
%9999 = tuple()
2164+
return %9999 : $()
2165+
}

0 commit comments

Comments
 (0)