@@ -56,6 +56,9 @@ sil @getNE : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow addr
5656sil @initTrivialHolder : $@convention(thin) () -> @out TrivialHolder
5757sil @getTrivialNE : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifetime(borrow address_for_deps 0) @owned NE
5858
59+ sil @makeHolder: $@convention(method) (@thin Holder.Type) -> @owned Holder // user: %6
60+ sil @getGeneric : $@convention(thin) <τ_0_0 where τ_0_0 : ~Escapable> (@guaranteed Holder, @thick τ_0_0.Type) -> @lifetime(borrow 0) @out τ_0_0 // user: %12
61+
5962// Test returning a owned dependence on a trivial value
6063sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
6164entry(%0 : @guaranteed $C):
@@ -163,3 +166,34 @@ bb0:
163166 %12 = tuple ()
164167 return %12
165168}
169+
170+ // Test a borrowed dependency on an address
171+ sil [ossa] @testBorrowAddress : $@convention(thin) <T where T : ~Escapable> (@thick T.Type) -> @lifetime(immortal) @out T {
172+ bb0(%0 : $*T, %1 : $@thick T.Type):
173+ debug_value %1, let, name "type", argno 1
174+ %3 = alloc_stack [lexical] [var_decl] $Holder, var, name "holder", type $Holder
175+ %4 = metatype $@thin Holder.Type
176+
177+ %5 = function_ref @makeHolder : $@convention(method) (@thin Holder.Type) -> @owned Holder
178+ %6 = apply %5(%4) : $@convention(method) (@thin Holder.Type) -> @owned Holder
179+ store %6 to [init] %3
180+ %8 = alloc_stack [lexical] [var_decl] $T, let, name "result"
181+ // expected-error @-1{{lifetime-dependent value escapes its scope}}
182+ %9 = begin_access [read] [static] %3
183+ // expected-note @-1{{it depends on this scoped access to variable}}
184+ %10 = load [copy] %9
185+
186+ %11 = function_ref @getGeneric : $@convention(thin) <τ_0_0 where τ_0_0 : ~Escapable> (@guaranteed Holder, @thick τ_0_0.Type) -> @lifetime(borrow 0) @out τ_0_0
187+ %12 = apply %11<T>(%8, %10, %1) : $@convention(thin) <τ_0_0 where τ_0_0 : ~Escapable> (@guaranteed Holder, @thick τ_0_0.Type) -> @lifetime(borrow 0) @out τ_0_0
188+ mark_dependence_addr [unresolved] %8 on %9
189+ destroy_value %10
190+ copy_addr %8 to [init] %0
191+ // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
192+ end_access %9
193+ destroy_addr %8
194+ dealloc_stack %8
195+ destroy_addr %3
196+ dealloc_stack %3
197+ %21 = tuple ()
198+ return %21
199+ }
0 commit comments