|
1 | 1 | // RUN: %target-swift-frontend -emit-silgen -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck %s
|
2 | 2 | // RUN: %target-swift-frontend -emit-sil -sil-verify-all -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck -check-prefix=SIL %s
|
3 | 3 |
|
| 4 | +class Klass {} |
| 5 | +struct S { |
| 6 | + var k = Klass() |
| 7 | +} |
| 8 | + |
4 | 9 | func doSomething() {}
|
5 | 10 |
|
6 | 11 | // Before the transformation, our access scope is not to end of scope... so
|
@@ -37,3 +42,32 @@ func testBindToVar() {
|
37 | 42 | inout x2 = x
|
38 | 43 | doSomething()
|
39 | 44 | }
|
| 45 | + |
| 46 | +// CHECK-LABEL: sil hidden [ossa] @$s18reference_bindings15testBindToInOutyySSzF : $@convention(thin) (@inout String) -> () { |
| 47 | +// CHECK: bb0([[ARG:%.*]] : $*String): |
| 48 | +// CHECK: [[BOX:%.*]] = alloc_box ${ var String } |
| 49 | +// CHECK: [[MARK:%.*]] = mark_unresolved_reference_binding [inout] [[BOX]] |
| 50 | +// CHECK: [[PROJECT:%.*]] = project_box [[MARK]] |
| 51 | +// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[ARG]] |
| 52 | +// CHECK: copy_addr [[ACCESS]] to [init] [[PROJECT]] |
| 53 | +// CHECK: end_access [[ACCESS]] |
| 54 | +// CHECK: apply {{%.*}}() |
| 55 | +// CHECK: destroy_value [[MARK]] |
| 56 | +// CHECK: } // end sil function '$s18reference_bindings15testBindToInOutyySSzF' |
| 57 | + |
| 58 | +// SIL-LABEL: sil hidden @$s18reference_bindings15testBindToInOutyySSzF : $@convention(thin) (@inout String) -> () { |
| 59 | +// SIL: bb0([[ARG:%.*]] : $*String): |
| 60 | +// SIL: [[STACK:%.*]] = alloc_stack $String |
| 61 | +// SIL: [[ACCESS:%.*]] = begin_access [modify] [static] [[ARG]] |
| 62 | +// SIL: [[VAL:%.*]] = load [[ACCESS]] |
| 63 | +// SIL: store [[VAL]] to [[STACK]] |
| 64 | +// SIL: apply {{%.*}} |
| 65 | +// SIL: [[VAL:%.*]] = load [[STACK]] |
| 66 | +// SIL: store [[VAL]] to [[ACCESS]] |
| 67 | +// SIL: end_access [[ACCESS]] |
| 68 | +// SIL: dealloc_stack [[STACK]] |
| 69 | +// SIL: } // end sil function '$s18reference_bindings15testBindToInOutyySSzF' |
| 70 | +func testBindToInOut(_ x: inout String) { |
| 71 | + inout y = x |
| 72 | + doSomething() |
| 73 | +} |
0 commit comments