Skip to content

Commit 2e7c29c

Browse files
committed
Restrict findSingleInitializer @out arguments.
The client should handle @in/@inout arguments differently.
1 parent fcb8612 commit 2e7c29c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ extension AccessBase {
199199
case let .stack(allocStack):
200200
baseAddr = allocStack
201201
case let .argument(arg):
202+
guard arg.convention.isIndirectOut else {
203+
return nil
204+
}
202205
baseAddr = arg
203206
default:
204207
return nil
@@ -208,7 +211,10 @@ extension AccessBase {
208211
== .abortWalk {
209212
return nil
210213
}
211-
return (initialAddress: baseAddr, initializingStore: walker.initializer!)
214+
guard let initializingStore = walker.initializingStore else {
215+
return nil
216+
}
217+
return (initialAddress: baseAddr, initializingStore: initializingStore)
212218
}
213219
}
214220

@@ -241,15 +247,15 @@ struct AddressInitializationWalker: AddressDefUseWalker, AddressUseVisitor {
241247
var walkDownCache = WalkerCache<SmallProjectionPath>()
242248

243249
var isProjected = false
244-
var initializer: Instruction?
250+
var initializingStore: Instruction?
245251

246252
private mutating func setInitializer(instruction: Instruction) -> WalkResult {
247253
// An initializer must be unique and store the full value.
248-
if initializer != nil || isProjected {
249-
initializer = nil
254+
if initializingStore != nil || isProjected {
255+
initializingStore = nil
250256
return .abortWalk
251257
}
252-
initializer = instruction
258+
initializingStore = instruction
253259
return .continueWalk
254260
}
255261
}

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ import SIL
6666
/// Value.enclosingAccess iteratively to find to AccessBase. This
6767
/// walker is useful for finding the innermost access, which may also
6868
/// be relevant for diagnostics.
69-
func gatherVariableIntroducers(for value: Value, _ context: Context) -> [Value]
69+
func gatherVariableIntroducers(for value: Value, _ context: Context)
70+
-> SingleInlineArray<Value>
7071
{
71-
var introducers: [Value] = []
72+
var introducers = SingleInlineArray<Value>()
7273
var useDefVisitor = VariableIntroducerUseDefWalker(context) {
73-
introducers.append($0)
74+
introducers.push($0)
7475
return .continueWalk
7576
}
7677
defer { useDefVisitor.deinitialize() }

0 commit comments

Comments
 (0)