Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ extension LifetimeDependence.Scope {
range.insert(inst)
case let li as LoadInst where li.loadOwnership == .take:
range.insert(inst)
case is EndBorrowInst:
range.insert(inst)
default:
break
}
Expand Down
25 changes: 25 additions & 0 deletions test/SILOptimizer/lifetime_dependence/verify_diagnostics.sil
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ struct NEObject : ~Escapable {
init()
}

public struct Holder {
var c: C
}

sil @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
sil @makeNEObject : $@convention(thin) () -> @lifetime(immortal) @owned NEObject
sil @useNE : $@convention(thin) (NE) -> ()

// Test returning a owned dependence on a trivial value
sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
Expand All @@ -55,3 +60,23 @@ entry(%0 : @guaranteed $C):
%mark = mark_dependence [unresolved] %call : $NEObject on %zero : $Builtin.Int1
return %mark // expected-note {{this use causes the lifetime-dependent value to escape}}
}

// OK: Test that the range initialized by a store_borrow covers dependent uses.
sil [ossa] @testStoreBorrowRange : $@convention(thin) (@owned Holder) -> () {
bb0(%0 : @owned $Holder):
%val = move_value [lexical] [var_decl] %0
%stk = alloc_stack $Holder
%sb = store_borrow %val to %stk
%f1 = function_ref @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
%c1 = apply %f1() : $@convention(thin) () -> @lifetime(immortal) @owned NE
%md = mark_dependence [unresolved] %c1 on %sb
%mv = move_value [var_decl] %md
%f2 = function_ref @useNE : $@convention(thin) (NE) -> ()
%c2 = apply %f2(%mv) : $@convention(thin) (NE) -> ()
destroy_value %mv
end_borrow %sb
dealloc_stack %stk
destroy_value %val
%99 = tuple ()
return %99
}