Skip to content

Commit

Permalink
Fix an incorrect iteration with a workList (#6177)
Browse files Browse the repository at this point in the history
* Fix an incorrect iteration with a workList

We cannot modify workList while iterating it, because its type `List` is
actually an array container.

* Change based on the feedback

* Use `Index` instead of `int` for for-loop index

---------

Co-authored-by: Yong He <[email protected]>
  • Loading branch information
jkwak-work and csyonghe authored Jan 27, 2025
1 parent 1f1892d commit da3dc98
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions source/slang/slang-ir-variable-scope-correction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ void VariableScopeCorrectionContext::_processFunction(IRFunc* funcInst)

auto instAfterParam = funcInst->getFirstBlock()->getFirstOrdinaryInst();

for (auto inst = workList.begin(); inst != workList.end(); inst++)
for (Index i = 0; i < workList.getCount(); i++)
{
if (auto loopHeaderList = loopHeaderMap.tryGetValue(getBlock(*inst)))
auto inst = workList[i];
if (auto loopHeaderList = loopHeaderMap.tryGetValue(getBlock(inst)))
{
_processInstruction(dominatorTree, instAfterParam, *inst, *loopHeaderList, workList);
_processInstruction(dominatorTree, instAfterParam, inst, *loopHeaderList, workList);
}
}
}
Expand Down

0 comments on commit da3dc98

Please sign in to comment.