Skip to content

Commit 33202a9

Browse files
committed
Fix DestroyHoisting: don't ignore pointer escapes.
A pointer escape means the liveness is incomplete. Don't hoist destroys with incomplete liveness.
1 parent ec6f9b5 commit 33202a9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DestroyHoisting.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ private func optimize(value: Value, _ context: FunctionPassContext) {
9191
var hoistableDestroys = selectHoistableDestroys(of: value, context)
9292
defer { hoistableDestroys.deinitialize() }
9393

94-
var minimalLiverange = InstructionRange(withLiverangeOf: value, ignoring: hoistableDestroys, context)
94+
guard var minimalLiverange = InstructionRange(withLiverangeOf: value, ignoring: hoistableDestroys, context) else {
95+
return
96+
}
9597
defer { minimalLiverange.deinitialize() }
9698

9799
hoistDestroys(of: value, toEndOf: minimalLiverange, restrictingTo: &hoistableDestroys, context)
@@ -177,7 +179,7 @@ private func removeDestroys(
177179

178180
private extension InstructionRange {
179181

180-
init(withLiverangeOf initialDef: Value, ignoring ignoreDestroys: InstructionSet, _ context: FunctionPassContext)
182+
init?(withLiverangeOf initialDef: Value, ignoring ignoreDestroys: InstructionSet, _ context: FunctionPassContext)
181183
{
182184
var liverange = InstructionRange(for: initialDef, context)
183185
var visitor = InteriorUseWalker(definingValue: initialDef, ignoreEscape: true, visitInnerUses: true, context) {
@@ -197,7 +199,9 @@ private extension InstructionRange {
197199
return .continueWalk
198200
}
199201

200-
_ = visitor.visitUses()
202+
guard visitor.visitUses() == .continueWalk else {
203+
return nil
204+
}
201205
self = liverange
202206
}
203207

0 commit comments

Comments
 (0)