Skip to content

Commit d9e7cf6

Browse files
committed
[Test] Added swift test for ShrinkBorrowScope.
The new file tests the -O pipeline up to just before OSSA lowering. It will be used for verifying the effects of ShrinkBorrowScope on swift code directly, to complement the tests done on SIL by just running a single pass.
1 parent 067efb1 commit d9e7cf6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-swift-frontend -c -O -enable-copy-propagation=true -enable-lexical-lifetimes=true -sil-verify-all -Xllvm -sil-print-final-ossa-module %s | %FileCheck %s
2+
3+
// =============================================================================
4+
// = DECLARATIONS {{
5+
// =============================================================================
6+
7+
@_silgen_name("consumeAndProduce")
8+
func consumeAndProduce(_ arg: __owned AnyObject) -> AnyObject
9+
10+
// =============================================================================
11+
// = DECLARATIONS }}
12+
// =============================================================================
13+
14+
// =============================================================================
15+
// = TESTS {{
16+
// =============================================================================
17+
18+
@_silgen_name("eliminate_copy_of_returned_then_consumed_owned_value")
19+
public func eliminate_copy_of_returned_then_consumed_owned_value(arg: __owned AnyObject) {
20+
// CHECK-LABEL: sil [ossa] @eliminate_copy_of_returned_then_consumed_owned_value : {{.*}} {
21+
// CHECK: {{bb[0-9]+}}([[ARG:%[^,]+]] : @owned $AnyObject):
22+
// retain arg
23+
// CHECK: [[ARG_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[ARG]]
24+
// CHECK: [[ARG_COPY:%[^,]+]] = copy_value [[ARG_LIFETIME]]
25+
let x = consumeAndProduce(arg)
26+
// CHECK: [[X:%[^,]+]] = apply {{%[^,]+}}([[ARG_COPY]])
27+
// no copy of 'x'
28+
_ = consumeAndProduce(x)
29+
// CHECK: [[RESULT:%[^,]+]] = apply {{%[^,]+}}([[X]])
30+
// CHECK: end_borrow [[ARG_LIFETIME]]
31+
// release result
32+
// release arg
33+
// CHECK: destroy_value [[RESULT]]
34+
// CHECK: destroy_value [[ARG]]
35+
// CHECK-LABEL: } // end sil function 'eliminate_copy_of_returned_then_consumed_owned_value'
36+
}
37+
38+
// =============================================================================
39+
// = TESTS }}
40+
// =============================================================================

0 commit comments

Comments
 (0)