Skip to content

Commit 91bdae7

Browse files
authored
Merge pull request #67918 from gottesmm/pr-c727b2c223717614f39877bf060a3d1797c03185
[reference-bindings] Add some more tests.
2 parents 708aedf + d915cf3 commit 91bdae7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/SILGen/reference_bindings.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// RUN: %target-swift-frontend -emit-silgen -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck %s
22
// RUN: %target-swift-frontend -emit-sil -sil-verify-all -enable-experimental-feature ReferenceBindings -o - %s | %FileCheck -check-prefix=SIL %s
33

4+
class Klass {}
5+
struct S {
6+
var k = Klass()
7+
}
8+
49
func doSomething() {}
510

611
// Before the transformation, our access scope is not to end of scope... so
@@ -37,3 +42,32 @@ func testBindToVar() {
3742
inout x2 = x
3843
doSomething()
3944
}
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

Comments
 (0)