Skip to content

Commit 45308f6

Browse files
committed
Try apply insts can also have guaranteed parameters.
This was a piece of code that was not updated with FullApplySite when try_apply was added. rdar://23505191
1 parent 5a48882 commit 45308f6

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

lib/SILAnalysis/ARCAnalysis.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,26 +577,28 @@ valueHasARCDecrementOrCheckInInstructionRange(SILValue Op,
577577
bool
578578
swift::
579579
mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
580-
// Only applies can require a guaranteed lifetime. If we don't have one, bail.
581-
auto *AI = dyn_cast<ApplyInst>(User);
582-
if (!AI)
580+
// Only full apply sites can require a guaranteed lifetime. If we don't have
581+
// one, bail.
582+
if (!isa<FullApplySite>(User))
583583
return false;
584584

585-
// Ok, we have an apply. If the apply has no arguments, we don't need to worry
586-
// about any guaranteed parameters.
587-
if (!AI->getNumOperands())
585+
FullApplySite FAS(User);
586+
587+
// Ok, we have a full apply site. If the apply has no arguments, we don't need
588+
// to worry about any guaranteed parameters.
589+
if (!FAS.getNumArguments())
588590
return false;
589591

590-
// Ok, we have an apply with arguments. Look at the function type and iterate
591-
// through the function parameters. If any of the parameters are guaranteed,
592-
// attempt to prove that the passed in parameter can not alias Ptr. If we
593-
// fail, return true.
594-
CanSILFunctionType FType = AI->getSubstCalleeType();
592+
// Ok, we have an apply site with arguments. Look at the function type and
593+
// iterate through the function parameters. If any of the parameters are
594+
// guaranteed, attempt to prove that the passed in parameter can not alias
595+
// Ptr. If we fail, return true.
596+
CanSILFunctionType FType = FAS.getSubstCalleeType();
595597
auto Params = FType->getParameters();
596598
for (unsigned i : indices(Params)) {
597599
if (!Params[i].isGuaranteed())
598600
continue;
599-
SILValue Op = AI->getArgument(i);
601+
SILValue Op = FAS.getArgument(i);
600602
for (int i = 0, e = Ptr->getNumTypes(); i < e; i++)
601603
if (!AA->isNoAlias(Op, SILValue(Ptr.getDef(), i)))
602604
return true;

test/SILPasses/globalarcopts.sil

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ enum Either<LTy, RTy> {
5252
case Right(RTy)
5353
}
5454

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

57-
sil @owned_return : $@convention(thin) () -> (@owned @box Builtin.Int32)
57+
sil [fragile] @owned_return : $@convention(thin) () -> (@owned @box Builtin.Int32)
58+
59+
sil [fragile] @guaranteed_throwing_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType
5860

5961
/////////////////
6062
// Basic Tests //
@@ -1907,3 +1909,25 @@ bb0:
19071909
%9999 = tuple()
19081910
return %9999 : $()
19091911
}
1912+
1913+
// CHECK-LABEL: sil [fragile] @try_apply_test : $@convention(thin) (Builtin.NativeObject) -> @error ErrorType {
1914+
// CHECK: bb0
1915+
// CHECK: strong_retain
1916+
// CHECK: bb1
1917+
// CHECK: strong_release
1918+
// CHECK: bb2
1919+
// CHECK: strong_release
1920+
sil [fragile] @try_apply_test : $@convention(thin) (Builtin.NativeObject) -> @error ErrorType {
1921+
bb0(%0 : $Builtin.NativeObject):
1922+
strong_retain %0 : $Builtin.NativeObject
1923+
%1 = function_ref @guaranteed_throwing_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType
1924+
try_apply %1(%0) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @error ErrorType, normal bb1, error bb2
1925+
1926+
bb1(%2 : $()):
1927+
strong_release %0 : $Builtin.NativeObject
1928+
return undef : $()
1929+
1930+
bb2(%3 : $ErrorType):
1931+
strong_release %0 : $Builtin.NativeObject
1932+
throw %3 : $ErrorType
1933+
}

validation-test/stdlib/OpenCLSDKOverlay.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33
// REQUIRES: OS=macosx
4-
// REQUIRES: rdar23505191
54

65
// Translated from standard OpenCL hello.c program
76

0 commit comments

Comments
 (0)