Skip to content

Commit 942ccd6

Browse files
committed
[Test] Add for PAI::visitOnStackLifetimeEnds.
1 parent 2befa41 commit 942ccd6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,22 @@ PartialApplyInst::visitOnStackLifetimeEnds(
19031903
return !noUsers;
19041904
}
19051905

1906+
namespace swift::test {
1907+
FunctionTest PartialApplyPrintOnStackLifetimeEnds(
1908+
"partial_apply_print_on_stack_lifetime_ends",
1909+
[](auto &function, auto &arguments, auto &test) {
1910+
auto *inst = arguments.takeInstruction();
1911+
auto *pai = cast<PartialApplyInst>(inst);
1912+
function.print(llvm::outs());
1913+
auto result = pai->visitOnStackLifetimeEnds([](auto *operand) {
1914+
operand->print(llvm::outs());
1915+
return true;
1916+
});
1917+
const char *resultString = result ? "true" : "false";
1918+
llvm::outs() << "returned: " << resultString << "\n";
1919+
});
1920+
} // end namespace swift::test
1921+
19061922
// FIXME: Rather than recursing through all results, this should only recurse
19071923
// through ForwardingInstruction and OwnershipTransitionInstruction and the
19081924
// client should prove that any other uses cannot be upstream from a consume of
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-sil-opt \
2+
// RUN: -test-runner \
3+
// RUN: %s \
4+
// RUN: -o /dev/null \
5+
// RUN: 2>&1 | %FileCheck %s
6+
7+
sil_stage canonical
8+
9+
class C {}
10+
11+
sil @borrowC : $@convention(thin) (@guaranteed C) -> ()
12+
13+
// CHECK-LABEL: begin running test {{.*}} on copied_partial_apply
14+
// CHECK-LABEL: sil [ossa] @copied_partial_apply : {{.*}} {
15+
// CHECK: bb0([[C:%[^,]+]] :
16+
// CHECK: [[BORROW_C:%[^,]+]] = function_ref @borrowC
17+
// CHECK: [[PA:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[BORROW_C]]([[C]])
18+
// CHECK: [[PA2:%[^,]+]] = copy_value [[PA]]
19+
// CHECK: destroy_value [[PA]]
20+
// CHECK: destroy_value [[PA2]]
21+
// CHECK: destroy_value [[C]]
22+
// CHECK-LABEL: } // end sil function 'copied_partial_apply'
23+
// CHECK: Operand.
24+
// CHECK: Owner: destroy_value [[PA]]
25+
// CHECK: returned: true
26+
// CHECK-LABEL: end running test {{.*}} on copied_partial_apply
27+
sil [ossa] @copied_partial_apply : $@convention(thin) (@owned C) -> () {
28+
entry(%c: @owned $C):
29+
specify_test "partial_apply_print_on_stack_lifetime_ends %pa"
30+
31+
%callee = function_ref @borrowC : $@convention(thin) (@guaranteed C) -> ()
32+
%pa = partial_apply [callee_guaranteed] [on_stack] %callee(%c) : $@convention(thin) (@guaranteed C) -> ()
33+
%pa2 = copy_value %pa
34+
destroy_value %pa
35+
36+
destroy_value %pa2
37+
destroy_value %c
38+
%retval = tuple ()
39+
return %retval
40+
}

0 commit comments

Comments
 (0)