File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/Utilities
test/SILOptimizer/lifetime_dependence Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -464,6 +464,8 @@ extension LifetimeDependence.Scope {
464464 range. insert ( inst)
465465 case let li as LoadInst where li. loadOwnership == . take:
466466 range. insert ( inst)
467+ case is EndBorrowInst :
468+ range. insert ( inst)
467469 default :
468470 break
469471 }
Original file line number Diff line number Diff line change @@ -29,8 +29,13 @@ struct NEObject : ~Escapable {
2929 init()
3030}
3131
32+ public struct Holder {
33+ var c: C
34+ }
35+
3236sil @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
3337sil @makeNEObject : $@convention(thin) () -> @lifetime(immortal) @owned NEObject
38+ sil @useNE : $@convention(thin) (NE) -> ()
3439
3540// Test returning a owned dependence on a trivial value
3641sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
@@ -55,3 +60,23 @@ entry(%0 : @guaranteed $C):
5560 %mark = mark_dependence [unresolved] %call : $NEObject on %zero : $Builtin.Int1
5661 return %mark // expected-note {{this use causes the lifetime-dependent value to escape}}
5762}
63+
64+ // OK: Test that the range initialized by a store_borrow covers dependent uses.
65+ sil [ossa] @testStoreBorrowRange : $@convention(thin) (@owned Holder) -> () {
66+ bb0(%0 : @owned $Holder):
67+ %val = move_value [lexical] [var_decl] %0
68+ %stk = alloc_stack $Holder
69+ %sb = store_borrow %val to %stk
70+ %f1 = function_ref @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
71+ %c1 = apply %f1() : $@convention(thin) () -> @lifetime(immortal) @owned NE
72+ %md = mark_dependence [unresolved] %c1 on %sb
73+ %mv = move_value [var_decl] %md
74+ %f2 = function_ref @useNE : $@convention(thin) (NE) -> ()
75+ %c2 = apply %f2(%mv) : $@convention(thin) (NE) -> ()
76+ destroy_value %mv
77+ end_borrow %sb
78+ dealloc_stack %stk
79+ destroy_value %val
80+ %99 = tuple ()
81+ return %99
82+ }
You can’t perform that action at this time.
0 commit comments