|
| 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