Skip to content

Commit

Permalink
Try apply insts can also have guaranteed parameters.
Browse files Browse the repository at this point in the history
This was a piece of code that was not updated with FullApplySite when try_apply
was added.

rdar://23505191
  • Loading branch information
gottesmm committed Nov 19, 2015
1 parent 5a48882 commit 45308f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
26 changes: 14 additions & 12 deletions lib/SILAnalysis/ARCAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,26 +577,28 @@ valueHasARCDecrementOrCheckInInstructionRange(SILValue Op,
bool
swift::
mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
// Only applies can require a guaranteed lifetime. If we don't have one, bail.
auto *AI = dyn_cast<ApplyInst>(User);
if (!AI)
// Only full apply sites can require a guaranteed lifetime. If we don't have
// one, bail.
if (!isa<FullApplySite>(User))
return false;

// Ok, we have an apply. If the apply has no arguments, we don't need to worry
// about any guaranteed parameters.
if (!AI->getNumOperands())
FullApplySite FAS(User);

// Ok, we have a full apply site. If the apply has no arguments, we don't need
// to worry about any guaranteed parameters.
if (!FAS.getNumArguments())
return false;

// Ok, we have an apply with arguments. Look at the function type and iterate
// through the function parameters. If any of the parameters are guaranteed,
// attempt to prove that the passed in parameter can not alias Ptr. If we
// fail, return true.
CanSILFunctionType FType = AI->getSubstCalleeType();
// Ok, we have an apply site with arguments. Look at the function type and
// iterate through the function parameters. If any of the parameters are
// guaranteed, attempt to prove that the passed in parameter can not alias
// Ptr. If we fail, return true.
CanSILFunctionType FType = FAS.getSubstCalleeType();
auto Params = FType->getParameters();
for (unsigned i : indices(Params)) {
if (!Params[i].isGuaranteed())
continue;
SILValue Op = AI->getArgument(i);
SILValue Op = FAS.getArgument(i);
for (int i = 0, e = Ptr->getNumTypes(); i < e; i++)
if (!AA->isNoAlias(Op, SILValue(Ptr.getDef(), i)))
return true;
Expand Down
28 changes: 26 additions & 2 deletions test/SILPasses/globalarcopts.sil
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ enum Either<LTy, RTy> {
case Right(RTy)
}

sil @guaranteed_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
sil [fragile] @guaranteed_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()

sil @owned_return : $@convention(thin) () -> (@owned @box Builtin.Int32)
sil [fragile] @owned_return : $@convention(thin) () -> (@owned @box Builtin.Int32)

sil [fragile] @guaranteed_throwing_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType

/////////////////
// Basic Tests //
Expand Down Expand Up @@ -1907,3 +1909,25 @@ bb0:
%9999 = tuple()
return %9999 : $()
}

// CHECK-LABEL: sil [fragile] @try_apply_test : $@convention(thin) (Builtin.NativeObject) -> @error ErrorType {
// CHECK: bb0
// CHECK: strong_retain
// CHECK: bb1
// CHECK: strong_release
// CHECK: bb2
// CHECK: strong_release
sil [fragile] @try_apply_test : $@convention(thin) (Builtin.NativeObject) -> @error ErrorType {
bb0(%0 : $Builtin.NativeObject):
strong_retain %0 : $Builtin.NativeObject
%1 = function_ref @guaranteed_throwing_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType
try_apply %1(%0) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType, normal bb1, error bb2

bb1(%2 : $()):
strong_release %0 : $Builtin.NativeObject
return undef : $()

bb2(%3 : $ErrorType):
strong_release %0 : $Builtin.NativeObject
throw %3 : $ErrorType
}
1 change: 0 additions & 1 deletion validation-test/stdlib/OpenCLSDKOverlay.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: OS=macosx
// REQUIRES: rdar23505191

// Translated from standard OpenCL hello.c program

Expand Down

0 comments on commit 45308f6

Please sign in to comment.