1
1
2
- // RUN: %target-swift-emit-silgen -module-name borrow -parse-stdlib %s | %FileCheck %s
2
+ // RUN: %target-swift-emit-silgen -enable-experimental-defined-lifetimes - module-name borrow -parse-stdlib %s | %FileCheck %s
3
3
4
4
import Swift
5
5
@@ -8,9 +8,12 @@ final class D {}
8
8
// Make sure that we insert the borrow for a ref_element_addr lvalue in the
9
9
// proper place.
10
10
final class C {
11
+ init ( ) { }
12
+ init ? ( failably: ( ) ) { }
11
13
var d : D = D ( )
12
14
}
13
15
16
+ func use< T> ( _ t: T ) { }
14
17
func useD( _ d: D ) { }
15
18
16
19
// CHECK-LABEL: sil hidden [ossa] @$s6borrow44lvalueBorrowShouldBeAtEndOfFormalAccessScope{{.*}} : $@convention(thin) () -> () {
@@ -33,3 +36,58 @@ func lvalueBorrowShouldBeAtEndOfFormalAccessScope() {
33
36
var c = C ( )
34
37
useD ( c. d)
35
38
}
39
+
40
+ // CHECK-LABEL: sil hidden [ossa] @defined_borrow_let_class
41
+ // CHECK: [[INIT_C:%[^,]+]] = function_ref @$s6borrow1CCACycfC
42
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[INIT_C]]({{%[0-9]+}})
43
+ // CHECK: [[BORROW:%[^,]+]] = begin_borrow [defined] [[INSTANCE]] : $C
44
+ // CHECK: end_borrow [[BORROW:%[^,]+]]
45
+ // CHECK-LABEL: } // end sil function 'defined_borrow_let_class'
46
+ @_silgen_name ( " defined_borrow_let_class " )
47
+ func defined_borrow_let_class( ) {
48
+ let c = C ( )
49
+ }
50
+
51
+ // CHECK-LABEL: sil hidden [ossa] @defined_borrow_if_let_class
52
+ // CHECK: [[INIT_C:%[^,]+]] = function_ref @$s6borrow1CC8failablyACSgyt_tcfC
53
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[INIT_C]]({{%[^,]+}})
54
+ // CHECK: switch_enum [[INSTANCE]] : $Optional<C>, case #Optional.some!enumelt: [[BASIC_BLOCK2:bb[^,]+]], case #Optional.none!enumelt: {{bb[^,]+}}
55
+ // CHECK: [[BASIC_BLOCK2]]([[INSTANCE:%[^,]+]] : @owned $C):
56
+ // CHECK: [[BORROW:%[^,]+]] = begin_borrow [defined] [[INSTANCE]] : $C
57
+ // CHECK: end_borrow [[BORROW]] : $C
58
+ // CHECK-LABEL: // end sil function 'defined_borrow_if_let_class'
59
+ @_silgen_name ( " defined_borrow_if_let_class " )
60
+ func defined_borrow_if_let_class( ) {
61
+ if let c = C ( failably: ( ) ) {
62
+ use ( ( ) )
63
+ }
64
+ }
65
+
66
+ struct S {
67
+ let c : C
68
+ }
69
+
70
+ // CHECK-LABEL: sil hidden [ossa] @defined_borrow_let_class_in_struct
71
+ // CHECK: [[INIT_S:%[^,]+]] = function_ref @$s6borrow1SV1cAcA1CC_tcfC
72
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[INIT_S]]({{%[0-9]+}}, {{%[0-9]+}})
73
+ // CHECK: [[BORROW:%[^,]+]] = begin_borrow [defined] [[INSTANCE]] : $S
74
+ // CHECK: end_borrow [[BORROW:%[^,]+]]
75
+ // CHECK-LABEL: } // end sil function 'defined_borrow_let_class_in_struct'
76
+ @_silgen_name ( " defined_borrow_let_class_in_struct " )
77
+ func defined_borrow_let_class_in_struct( ) {
78
+ let s = S ( c: C ( ) )
79
+ }
80
+
81
+ enum E {
82
+ case e( C )
83
+ }
84
+
85
+ // CHECK-LABEL: sil hidden [ossa] @defined_borrow_let_class_in_enum
86
+ // CHECK: [[INSTANCE:%[^,]+]] = enum $E, #E.e!enumelt, {{%[0-9]+}} : $C
87
+ // CHECK: [[BORROW:%[^,]+]] = begin_borrow [defined] [[INSTANCE]] : $E
88
+ // CHECK: end_borrow [[BORROW:%[^,]+]]
89
+ // CHECK-LABEL: } // end sil function 'defined_borrow_let_class_in_enum'
90
+ @_silgen_name ( " defined_borrow_let_class_in_enum " )
91
+ func defined_borrow_let_class_in_enum( ) {
92
+ let s = E . e ( C ( ) )
93
+ }
0 commit comments