Skip to content

Commit 2647e08

Browse files
committed
[OSSA] Fix ApplyInstBase::getCalleeOrigin for copy_value.
1 parent 75e7f71 commit 2647e08

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9053,6 +9053,10 @@ SILValue ApplyInstBase<Impl, Base, false>::getCalleeOrigin() const {
90539053
Callee = beginBorrow->getOperand();
90549054
continue;
90559055
}
9056+
if (auto *copy = dyn_cast<CopyValueInst>(Callee)) {
9057+
Callee = copy->getOperand();
9058+
continue;
9059+
}
90569060
return Callee;
90579061
}
90589062
}

test/SILOptimizer/accessed_storage_analysis.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,31 @@ bb0(%0 : $Int):
527527
return %v : $()
528528
}
529529

530+
// CHECK-LABEL: @testCopiedNoEscape
531+
// CHECK: [read] Stack %3 = alloc_stack $Int
532+
sil [ossa] @testCopiedNoEscape : $@convention(thin) (Int) -> () {
533+
bb0(%0 : $Int):
534+
%s1 = alloc_stack $Int
535+
store %0 to [trivial] %s1 : $*Int
536+
%s2 = alloc_stack $Int
537+
store %0 to [trivial] %s2 : $*Int
538+
%f = function_ref @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
539+
%pa = partial_apply [callee_guaranteed] %f(%s2) : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
540+
%copy = copy_value %pa : $@callee_guaranteed (@inout Int) -> ()
541+
%borrow = begin_borrow %copy : $@callee_guaranteed (@inout Int) -> ()
542+
%npa = convert_escape_to_noescape %borrow : $@callee_guaranteed (@inout Int) -> () to $@noescape @callee_guaranteed (@inout Int) -> ()
543+
%access = begin_access [modify] [dynamic] %s1 : $*Int
544+
%call = apply %npa(%access) : $@noescape @callee_guaranteed (@inout Int) -> ()
545+
end_access %access : $*Int
546+
end_borrow %borrow : $@callee_guaranteed (@inout Int) -> ()
547+
destroy_value %copy : $@callee_guaranteed (@inout Int) -> ()
548+
destroy_value %pa : $@callee_guaranteed (@inout Int) -> ()
549+
dealloc_stack %s2 : $*Int
550+
dealloc_stack %s1 : $*Int
551+
%v = tuple ()
552+
return %v : $()
553+
}
554+
530555
// CHECK: @testDirectlyAppliedClosure
531556
// CHECK: [read] Argument %1 = argument of bb0 : $*Int
532557
sil private @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> () {

0 commit comments

Comments
 (0)