|
| 1 | +// RUN: %target-swift-frontend %s -emit-sil \ |
| 2 | +// RUN: -sil-verify-all \ |
| 3 | +// RUN: -module-name test \ |
| 4 | +// RUN: -disable-experimental-parser-round-trip \ |
| 5 | +// RUN: -enable-experimental-feature NonescapableTypes \ |
| 6 | +// RUN: -Xllvm -enable-lifetime-dependence-insertion \ |
| 7 | +// RUN: 2>&1 | %FileCheck %s |
| 8 | + |
| 9 | +// REQUIRES: swift_in_compiler |
| 10 | + |
| 11 | +@_nonescapable |
| 12 | +struct BV { |
| 13 | + let p: UnsafeRawPointer |
| 14 | + let i: Int |
| 15 | + |
| 16 | + @_unsafeNonescapableResult |
| 17 | + init(_ p: UnsafeRawPointer, _ i: Int) { |
| 18 | + self.p = p |
| 19 | + self.i = i |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +struct NC : ~Copyable { |
| 24 | + let p: UnsafeRawPointer |
| 25 | + let i: Int |
| 26 | + |
| 27 | + // Requires a borrow. |
| 28 | + borrowing func getBV() -> _borrow(self) BV { |
| 29 | + BV(p, i) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +@_silgen_name("use") |
| 34 | +func use(_ o : borrowing BV) |
| 35 | + |
| 36 | +// CHECK-LABEL: sil hidden @$s4test13bv_borrow_var1p1iySV_SitF : $@convention(thin) (UnsafeRawPointer, Int) -> () { |
| 37 | +// CHECK: [[A:%.*]] = begin_access [read] [static] %{{.*}} : $*NC |
| 38 | +// CHECK: [[L:%.*]] = load [[A]] : $*NC |
| 39 | +// CHECK: [[R:%.*]] = apply %{{.*}}([[L]]) : $@convention(method) (@guaranteed NC) -> _scope(0) @owned BV |
| 40 | +// CHECK: [[M:%.*]] = mark_dependence [unresolved] [[R]] : $BV on [[A]] : $*NC |
| 41 | +// CHECK: end_access [[A]] : $*NC |
| 42 | +// CHECK: %{{.*}} = apply %{{.*}}([[M]]) : $@convention(thin) (@guaranteed BV) -> () |
| 43 | +// CHECK-LABEL: } // end sil function '$s4test13bv_borrow_var1p1iySV_SitF' |
| 44 | +func bv_borrow_var(p: UnsafeRawPointer, i: Int) { |
| 45 | + var nc = NC(p: p, i: i) |
| 46 | + let bv = nc.getBV() |
| 47 | + use(bv) |
| 48 | +} |
0 commit comments