@@ -27,6 +27,7 @@ class WeakCycle {
2727 weak var c: WeakCycle?
2828}
2929
30+ sil [ossa] @$s24diagnose_lifetime_issues8DelegateCACycfC : $@convention(method) (@thick Delegate.Type) -> @owned Delegate
3031sil [ossa] @$s24diagnose_lifetime_issues10MyDelegateCACycfC : $@convention(method) (@thick MyDelegate.Type) -> @owned MyDelegate
3132sil [ossa] @$s24diagnose_lifetime_issues14strongDelegate1dyAA0D0C_tF : $@convention(method) (@guaranteed Delegate, @guaranteed Container) -> ()
3233
@@ -119,3 +120,41 @@ bb0(%0 : $@thick WeakCycle.Type):
119120 %3 = apply %2(%1) : $@convention(method) (@owned WeakCycle) -> @owned WeakCycle
120121 return %3 : $WeakCycle
121122}
123+
124+ // Helper
125+ sil private [ossa] @testBorrowInDefer$defer : $@convention(thin) (@guaranteed Delegate) -> () {
126+ bb0(%0 : @closureCapture @guaranteed $Delegate):
127+ debug_value %0 : $Delegate, let, name "delegate", argno 1
128+ fix_lifetime %0 : $Delegate
129+ %8 = tuple ()
130+ return %8 : $()
131+ }
132+
133+ // Test no warning for a value kept alive within a call which does not escape its argument.
134+ sil hidden [ossa] @testBorrowinDefer : $@convention(thin) (@guaranteed Container) -> () {
135+ bb0(%0 : @guaranteed $Container):
136+ debug_value %0 : $Container, let, name "container", argno 1
137+ %2 = metatype $@thick Delegate.Type
138+ // function_ref Delegate.__allocating_init()
139+ %3 = function_ref @$s24diagnose_lifetime_issues8DelegateCACycfC : $@convention(method) (@thick Delegate.Type) -> @owned Delegate
140+
141+ // This is the owned allocation.
142+ %4 = apply %3(%2) : $@convention(method) (@thick Delegate.Type) -> @owned Delegate
143+ %6 = copy_value %4 : $Delegate
144+ %7 = enum $Optional<Delegate>, #Optional.some!enumelt, %6 : $Delegate
145+ %8 = ref_element_addr %0 : $Container, #Container.delegate
146+ %9 = begin_access [modify] [dynamic] %8 : $*@sil_weak Optional<Delegate>
147+
148+ // This is the weak assignment.
149+ store_weak %7 to %9 : $*@sil_weak Optional<Delegate>
150+ destroy_value %7 : $Optional<Delegate>
151+ end_access %9 : $*@sil_weak Optional<Delegate>
152+
153+ // This call keeps the parent alive
154+ %15 = function_ref @testBorrowInDefer$defer : $@convention(thin) (@guaranteed Delegate) -> () // user: %16
155+ %16 = apply %15(%4) : $@convention(thin) (@guaranteed Delegate) -> ()
156+
157+ destroy_value %4 : $Delegate
158+ %18 = tuple ()
159+ return %18 : $()
160+ }
0 commit comments