Skip to content

Commit 56126e9

Browse files
committed
Fix LetPropertyLowering to correctly find mark_uninitialized uses.
1 parent a7e4e90 commit 56126e9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LetPropertyLowering.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ private func constructLetInitRegion(
162162
initRegion.insert(inst)
163163

164164
case let beginBorrow as BeginBorrowInst
165-
where beginBorrow.borrowedValue.referenceRoot == markUninitialized:
165+
where beginBorrow.borrowedValue.isReferenceDerived(from: markUninitialized):
166166
borrows.append(beginBorrow)
167167

168168
case let storeBorrow as StoreBorrowInst
169-
where storeBorrow.source.referenceRoot == markUninitialized:
169+
where storeBorrow.source.isReferenceDerived(from: markUninitialized):
170170
borrows.append(storeBorrow)
171171

172172
default:
@@ -202,10 +202,28 @@ private extension RefElementAddrInst {
202202
}
203203

204204
private extension Value {
205+
func isReferenceDerived(from root: Value) -> Bool {
206+
var parent: Value = self
207+
while true {
208+
if parent == root {
209+
return true
210+
}
211+
if let operand = parent.forwardingInstruction?.singleForwardedOperand {
212+
parent = operand.value
213+
continue
214+
}
215+
if let transition = parent.definingInstruction as? OwnershipTransitionInstruction {
216+
parent = transition.operand.value
217+
continue
218+
}
219+
return false
220+
}
221+
}
222+
205223
func isLetFieldAddress(of markUninitialized: MarkUninitializedInst) -> Bool {
206224
if case .class(let rea) = self.accessBase,
207225
rea.fieldIsLet,
208-
rea.instance.referenceRoot == markUninitialized
226+
rea.instance.isReferenceDerived(from: markUninitialized)
209227
{
210228
return true
211229
}

0 commit comments

Comments
 (0)