1
1
// RUN: %target-sil-opt -test-runner %s \
2
2
// RUN: -diagnostics -sil-verify-all \
3
3
// RUN: -enable-experimental-feature LifetimeDependence \
4
+ // RUN: -enable-experimental-feature Span \
4
5
// RUN: 2>&1 | %FileCheck %s
5
6
6
7
// Test SIL expected from SILGen output. Run all diagnostic passes which includes lifetime dependence handling:
12
13
13
14
// REQUIRES: swift_in_compiler
14
15
// REQUIRES: swift_feature_LifetimeDependence
16
+ // REQUIRES: swift_feature_Span
15
17
16
18
sil_stage raw
17
19
@@ -23,9 +25,15 @@ struct Owner {}
23
25
struct NE: ~Escapable {}
24
26
struct OtherNE: ~Escapable {}
25
27
28
+ public struct Container {
29
+ var pointer: UnsafeRawPointer
30
+ var object: AnyObject
31
+ }
32
+
26
33
sil @getNE : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @autoreleased NE
27
34
sil @copyNE : $@convention(c) (NE, @lifetime(copy 0) @inout NE) -> ()
28
35
sil @makeOwner : $@convention(c) () -> Owner
36
+ sil @_overrideLifetimeBorrowing : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable, τ_0_1 : ~Copyable, τ_0_1 : ~Escapable> (@in τ_0_0, @in_guaranteed τ_0_1) -> @lifetime(borrow 1) @out τ_0_0
29
37
30
38
// Modify a local via 'inout' assignment.
31
39
// Do not insert a mark_dep.
@@ -129,3 +137,64 @@ bb0:
129
137
%93 = tuple ()
130
138
return %93 : $()
131
139
}
140
+
141
+ // Init.init()
142
+ sil @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
143
+ // RawSpan.init()
144
+ sil @$ss7RawSpanV12_unsafeStart9byteCountABSV_SitcfC : $@convention(method) (UnsafeRawPointer, Int, @thin RawSpan.Type) -> @lifetime(borrow 0) @owned RawSpan
145
+
146
+ // Test dependence on an in_guaranteed address and a store_borrow.
147
+ //
148
+ // A mark_dependence will be created for %23 apply, but OnonSimplify will later remove it.
149
+ //
150
+ // CHECK-LABEL: sil [available 9999] [ossa] @testInGuaranteedRawSpan : $@convention(method) (@in_guaranteed Container) -> @lifetime(borrow 0) @owned RawSpan {
151
+ // CHECK: bb0(%0 : $*Container):
152
+ // CHECK: [[GETSPAN:%.*]] = apply %{{.*}}({{.*}}) : $@convention(method) (UnsafeRawPointer, Int, @thin RawSpan.Type) -> @lifetime(borrow 0) @owned RawSpan
153
+ // CHECK: mark_dependence [nonescaping] [[GETSPAN]] on %0
154
+ // CHECK: [[OUT:%.*]] = alloc_stack $RawSpan
155
+ // CHECK: [[IN:%.*]] = alloc_stack $RawSpan
156
+ // CHECK: store %{{.*}} to [init] [[IN]]
157
+ // CHECK: [[LB:%.*]] = load_borrow %0
158
+ // CHECK: [[BORROWSELF:%.*]] = alloc_stack $Container
159
+ // CHECK: [[SB:%.*]] = store_borrow [[LB]] to [[BORROWSELF]]
160
+ // CHECK: apply %{{.*}}<RawSpan, Container>([[OUT]], [[IN]], [[SB]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable, τ_0_1 : ~Copyable, τ_0_1 : ~Escapable> (@in τ_0_0, @in_guaranteed τ_0_1) -> @lifetime(borrow 1) @out τ_0_0
161
+ // CHECK: [[RET:%.*]] = load [take] [[OUT]]
162
+ // CHECK: return [[RET]]
163
+ // CHECK-LABEL: } // end sil function 'testInGuaranteedRawSpan'
164
+ sil [available 9999] [ossa] @testInGuaranteedRawSpan : $@convention(method) (@in_guaranteed Container) -> @lifetime(borrow 0) @owned RawSpan {
165
+ bb0(%0 : $*Container):
166
+ debug_value %0, let, name "self", argno 1, expr op_deref
167
+ %2 = metatype $@thin RawSpan.Type
168
+ %3 = load_borrow %0
169
+ %4 = struct_extract %3, #Container.pointer
170
+ %5 = integer_literal $Builtin.IntLiteral, 0
171
+ %6 = metatype $@thin Int.Type
172
+ %7 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
173
+ %8 = apply %7(%5, %6) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
174
+
175
+ %9 = function_ref @$ss7RawSpanV12_unsafeStart9byteCountABSV_SitcfC : $@convention(method) (UnsafeRawPointer, Int, @thin RawSpan.Type) -> @lifetime(borrow 0) @owned RawSpan
176
+ %10 = apply %9(%4, %8, %2) : $@convention(method) (UnsafeRawPointer, Int, @thin RawSpan.Type) -> @lifetime(borrow 0) @owned RawSpan
177
+ end_borrow %3
178
+ %12 = move_value [var_decl] %10
179
+ debug_value %12, let, name "span"
180
+ %14 = alloc_stack $RawSpan
181
+ %15 = begin_borrow %12
182
+ %16 = copy_value %15
183
+ %17 = alloc_stack $RawSpan
184
+ store %16 to [init] %17
185
+ %19 = load_borrow %0
186
+ %20 = alloc_stack $Container
187
+ %21 = store_borrow %19 to %20
188
+
189
+ %22 = function_ref @_overrideLifetimeBorrowing : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable, τ_0_1 : ~Copyable, τ_0_1 : ~Escapable> (@in τ_0_0, @in_guaranteed τ_0_1) -> @lifetime(borrow 1) @out τ_0_0
190
+ %23 = apply %22<RawSpan, Container>(%14, %17, %21) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable, τ_0_1 : ~Copyable, τ_0_1 : ~Escapable> (@in τ_0_0, @in_guaranteed τ_0_1) -> @lifetime(borrow 1) @out τ_0_0
191
+ end_borrow %21
192
+ dealloc_stack %20
193
+ end_borrow %19
194
+ dealloc_stack %17
195
+ end_borrow %15
196
+ %29 = load [take] %14
197
+ dealloc_stack %14
198
+ destroy_value %12
199
+ return %29
200
+ }
0 commit comments