Skip to content

Commit ee599d8

Browse files
committed
DiagnoseInfiniteRecursion: correctly handle multi-result instructions when checking for invariant arguments.
Use `getDefiningInstruction` instead of casting a a SILValue to SingleValueInstruction.
1 parent baab923 commit ee599d8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/SILOptimizer/Mandatory/DiagnoseInfiniteRecursion.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,13 @@ class Invariants {
158158
/// Recursively walks the use-def chain starting at \p value and returns
159159
/// true if all visited values are invariant.
160160
bool isInvariantValue(SILValue value,
161-
SmallPtrSetImpl<SILNode *> &visited) const {
162-
SILNode *node = value->getRepresentativeSILNodeInObject();
161+
SmallPtrSetImpl<SILInstruction *> &visited) const {
162+
if (SILInstruction *inst = value->getDefiningInstruction()) {
163+
// Avoid exponential complexity in case a value is used by multiple
164+
// operands.
165+
if (!visited.insert(inst).second)
166+
return true;
163167

164-
// Avoid exponential complexity in case a value is used by multiple
165-
// operands.
166-
if (!visited.insert(node).second)
167-
return true;
168-
169-
if (auto *inst = dyn_cast<SILInstruction>(node)) {
170168
if (!isMemoryInvariant() && inst->mayReadFromMemory())
171169
return false;
172170

@@ -228,7 +226,7 @@ class Invariants {
228226
case TermKind::SwitchEnumInst:
229227
case TermKind::CheckedCastBranchInst:
230228
case TermKind::CheckedCastValueBranchInst: {
231-
SmallPtrSet<SILNode *, 16> visited;
229+
SmallPtrSet<SILInstruction *, 16> visited;
232230
return isInvariantValue(term->getOperand(0), visited);
233231
}
234232
default:

0 commit comments

Comments
 (0)