Merge pull request #81246 from atrick/rdar150403948-lifedep-walker-recurse

LifetimeDependenceDefUseAddressWalker: avoid infinite recursion.
This commit is contained in:
Andrew Trick
2025-05-02 00:46:37 -07:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -424,6 +424,10 @@ struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefValueWalker, Lif
visitedValues.insert(value)
}
mutating func needWalk(for address: Value) -> Bool {
visitedValues.insert(address)
}
mutating func walkUp(newLifetime: Value) -> WalkResult {
if newLifetime.type.isAddress {
return walkUp(address: newLifetime)

View File

@@ -817,7 +817,10 @@ extension LifetimeDependenceDefUseWalker {
}
private mutating func walkDownAddressUses(of address: Value) -> WalkResult {
address.uses.ignoreTypeDependence.walk {
if !needWalk(for: address) {
return .continueWalk
}
return address.uses.ignoreTypeDependence.walk {
return classifyAddress(operand: $0)
}
}
@@ -1199,6 +1202,8 @@ protocol LifetimeDependenceUseDefAddressWalker {
// ignored.
var isTrivialScope: Bool { get }
mutating func needWalk(for address: Value) -> Bool
mutating func addressIntroducer(_ address: Value, access: AccessBaseAndScopes) -> WalkResult
// The 'newLifetime' value is not forwarded to its uses. It may be a non-address or an address.
@@ -1221,6 +1226,9 @@ extension LifetimeDependenceUseDefAddressWalker {
}
mutating func walkUpDefault(address: Value, access: AccessBaseAndScopes) -> WalkResult {
if !needWalk(for: address) {
return .continueWalk
}
if let beginAccess = access.innermostAccess {
// Skip the access scope for unsafe[Mutable]Address. Treat it like a projection of 'self' rather than a separate
// variable access.
@@ -1333,6 +1341,10 @@ struct LifetimeDependenceRootWalker : LifetimeDependenceUseDefValueWalker, Lifet
visitedValues.insert(value)
}
mutating func needWalk(for address: Value) -> Bool {
visitedValues.insert(address)
}
mutating func walkUp(newLifetime: Value) -> WalkResult {
if newLifetime.type.isAddress {
return walkUp(address: newLifetime)