Skip to content

Commit 3019c84

Browse files
committed
LifetimeDependence: allow dependence on the store_borrow address
Previously, the dependence was on the stored value, but that is incorrect for '@'_addressable parameters.
1 parent e888d96 commit 3019c84

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ struct LifetimeDependence : CustomStringConvertible {
105105
case let .initialized(initializer):
106106
let initialAddress = initializer.initialAddress
107107
precondition(initialAddress.type.isAddress, "expected an address")
108-
precondition(initialAddress is AllocStackInst || initialAddress is FunctionArgument,
108+
precondition(initialAddress is AllocStackInst || initialAddress is FunctionArgument
109+
|| initialAddress is StoreBorrowInst,
109110
"expected storage for a a local 'let'")
110111
if case let .store(store, _) = initializer {
111-
precondition(store is StoringInstruction || store is SourceDestAddrInstruction || store is FullApplySite,
112+
precondition(store is StoringInstruction || store is SourceDestAddrInstruction || store is FullApplySite
113+
|| store is StoreBorrowInst,
112114
"expected a store")
113115
}
114116
}
@@ -217,8 +219,8 @@ extension LifetimeDependence.Scope {
217219
/// Construct a lifetime dependence scope from the base value that other values depend on. This derives the kind of
218220
/// dependence scope and its parentValue from `base`.
219221
///
220-
/// The returned Scope must be the only scope for the given 'base' value. This is generally non-recursive, except
221-
/// that finds the single borrow introducer. Use-def walking is handled by a utility such as
222+
/// The returned Scope must be the only scope for the given 'base' value. This is generally non-recursive, except
223+
/// that it tries to find the single borrow introducer. General use-def walking is handled by a utility such as
222224
/// VariableIntroducerUseDefWalker, which can handle multiple introducers.
223225
///
224226
/// `base` represents the OSSA lifetime that the dependent value must be used within. If `base` is owned, then it
@@ -291,7 +293,8 @@ extension LifetimeDependence.Scope {
291293
case let .yield(result):
292294
self.init(yield: result)
293295
case .storeBorrow(let sb):
294-
self = Self(base: sb.source, context)
296+
// Don't follow the stored value in case the dependence requires addressability.
297+
self = .initialized(.store(initializingStore: sb, initialAddress: sb))
295298
}
296299
}
297300

0 commit comments

Comments
 (0)