Skip to content

Commit cefedf2

Browse files
authored
🐛 do not invalidate iterator in block collection (#808)
## Description This fixes a small bug observed as part of #803, which only surfaced on Windows in Debug mode when compiling using Clang 🤯 Part of the block collection code in the circuit optimizer would invalidate an iterator due to an update of the respective container being iterated over within the loop. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines. Signed-off-by: Lukas Burgholzer <[email protected]>
1 parent ed00fb4 commit cefedf2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/circuit_optimizer/CircuitOptimizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,10 @@ struct DSU {
14141414
} else {
14151415
*currentBlockInCircuit[block] = std::move(compoundOp);
14161416
}
1417-
for (auto i : bitBlocks[block]) {
1417+
// need to make a copy here because otherwise the updates in the loop might
1418+
// invalidate the iterator
1419+
const auto blockBits = bitBlocks[block];
1420+
for (auto i : blockBits) {
14181421
parent[i] = i;
14191422
bitBlocks[i] = {i};
14201423
currentBlockInCircuit[i] = nullptr;

0 commit comments

Comments
 (0)