Skip to content

Commit bcc8add

Browse files
authored
Merge pull request #42233 from atrick/5.7-test-disable-lifetime
[5.7] Add test case for disabling lexical lifetimes.
2 parents b4b9c5e + 5ae9cf8 commit bcc8add

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-swift-frontend -emit-sil -O -parse-as-library -enable-copy-propagation=false -Xllvm -sil-print-all -module-name=main %s 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-sil -O -parse-as-library -enable-lexical-lifetimes=false -Xllvm -sil-print-all -module-name=main %s 2>&1 | %FileCheck %s
3+
4+
@inline(never)
5+
func takeGuaranteed(_ a: AnyObject) -> AnyObject {
6+
return a
7+
}
8+
9+
// CHECK-LABEL: // testLexical(a:)
10+
// CHECK: [[B:%.*]] = begin_borrow [lexical] %0
11+
// CHECK: apply %{{.*}}([[B]])
12+
// CHECK: apply
13+
// CHECK: end_borrow [[B]]
14+
// CHECK-LABEL: } // end sil function
15+
16+
// LexicalLifetimeEliminator must strip the [lexical] flag
17+
// before the first round of SemanticARCOpts.
18+
19+
// CHECK-NOT: *** SIL function after {{.*}} (semantic-arc-opts)
20+
21+
// CHECK-LABEL: *** SIL function after {{.*}} (sil-lexical-lifetime-eliminator)
22+
// CHECK-LABEL: // testLexical(a:)
23+
// CHECK: [[B:%.*]] = begin_borrow %0
24+
// CHECK: apply %{{.*}}([[B]])
25+
// CHECK: apply
26+
// CHECK: end_borrow [[B]]
27+
// CHECK-LABEL: } // end sil function
28+
29+
// The first round of SemanticARCOpts must eliminate the borrow scope
30+
// that was only needed for a lexical lifetime.
31+
32+
// CHECK-LABEL: *** SIL function after {{.*}} (semantic-arc-opts)
33+
// CHECK-LABEL: // testLexical(a:)
34+
// CHECK: apply %{{.*}}(%0)
35+
// CHECK-LABEL: } // end sil function
36+
public func testLexical(a: __owned AnyObject) -> AnyObject {
37+
// Without lexical lifetimes, the lifetime of 'a' ends in between the two calls:
38+
return takeGuaranteed(takeGuaranteed(a))
39+
}

0 commit comments

Comments
 (0)