1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// RUN: %target-swift-frontend -emit-silgen -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-sil -sil-verify-all -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck -check-prefix=SIL %s
class Klass {}
struct S {
var k = Klass()
}
func doSomething() {}
// Before the transformation, our access scope is not to end of scope... so
// doSomething() is not within the access scope.
//
// CHECK-LABEL: sil hidden [ossa] @$s18reference_bindings13testBindToVaryyF : $@convention(thin) () -> () {
// CHECK: [[BOX:%.*]] = alloc_box ${ var Int }, var, name "x"
// CHECK: [[LIFETIME:%.*]] = begin_borrow [var_decl] %0
// CHECK: [[PROJECT:%.*]] = project_box [[LIFETIME]]
// CHECK: [[INOUT_BOX:%.*]] = alloc_box ${ var Int }, var, name "x2"
// CHECK: [[UNRESOLVED_BINDING:%.*]] = mark_unresolved_reference_binding [inout] [[INOUT_BOX]]
// CHECK: [[INOUT_LIFETIME:%.*]] = begin_borrow [var_decl] [[UNRESOLVED_BINDING]]
// CHECK: [[INOUT_PROJECT:%.*]] = project_box [[INOUT_LIFETIME]]
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[PROJECT]]
// CHECK: copy_addr [[ACCESS]] to [init] [[INOUT_PROJECT]]
// CHECK: end_access [[ACCESS]]
// CHECK: [[FUNC:%.*]] = function_ref @$s18reference_bindings11doSomethingyyF : $@convention(thin) () -> ()
// CHECK: apply [[FUNC]]()
// CHECK: destroy_value [[UNRESOLVED_BINDING]]
// CHECK: destroy_value [[BOX]]
// CHECK: } // end sil function '$s18reference_bindings13testBindToVaryyF'
// SIL: sil hidden @$s18reference_bindings13testBindToVaryyF : $@convention(thin) () -> () {
// SIL: bb0:
// SIL: [[BOX:%.*]] = alloc_stack [var_decl] $Int, var, name "x"
// SIL: [[INOUT_BOX:%.*]] = alloc_stack [var_decl] $Int, var, name "x2"
// SIL: [[ACCESS:%.*]] = begin_access [modify] [static] [[BOX]]
// SIL: store {{%.*}} to [[INOUT_BOX]]
// SIL: [[FUNC:%.*]] = function_ref @$s18reference_bindings11doSomethingyyF : $@convention(thin) () -> ()
// SIL: apply [[FUNC]]()
// SIL: store {{%.*}} to [[ACCESS]]
// SIL: end_access [[ACCESS]]
// SIL: } // end sil function '$s18reference_bindings13testBindToVaryyF'
func testBindToVar() {
var x = 5
inout x2 = x
doSomething()
}
// CHECK-LABEL: sil hidden [ossa] @$s18reference_bindings15testBindToInOutyySSzF : $@convention(thin) (@inout String) -> () {
// CHECK: bb0([[ARG:%.*]] : $*String):
// CHECK: [[BOX:%.*]] = alloc_box ${ var String }
// CHECK: [[MARK:%.*]] = mark_unresolved_reference_binding [inout] [[BOX]]
// CHECK: [[LIFETIME:%.*]] = begin_borrow [var_decl] [[MARK]]
// CHECK: [[PROJECT:%.*]] = project_box [[LIFETIME]]
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[ARG]]
// CHECK: copy_addr [[ACCESS]] to [init] [[PROJECT]]
// CHECK: end_access [[ACCESS]]
// CHECK: apply {{%.*}}()
// CHECK: destroy_value [[MARK]]
// CHECK: } // end sil function '$s18reference_bindings15testBindToInOutyySSzF'
// SIL-LABEL: sil hidden @$s18reference_bindings15testBindToInOutyySSzF : $@convention(thin) (@inout String) -> () {
// SIL: bb0([[ARG:%.*]] : $*String):
// SIL: [[STACK:%.*]] = alloc_stack [var_decl] $String
// SIL: [[ACCESS:%.*]] = begin_access [modify] [static] [[ARG]]
// SIL: [[VAL:%.*]] = load [[ACCESS]]
// SIL: store [[VAL]] to [[STACK]]
// SIL: apply {{%.*}}
// SIL: [[VAL:%.*]] = load [[STACK]]
// SIL: store [[VAL]] to [[ACCESS]]
// SIL: end_access [[ACCESS]]
// SIL: dealloc_stack [[STACK]]
// SIL: } // end sil function '$s18reference_bindings15testBindToInOutyySSzF'
func testBindToInOut(_ x: inout String) {
inout y = x
doSomething()
}
|