Skip to content

Commit

Permalink
🐛 do not invalidate iterator in block collection (#808)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
burgholzer authored Jan 21, 2025
1 parent ed00fb4 commit cefedf2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/circuit_optimizer/CircuitOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,10 @@ struct DSU {
} else {
*currentBlockInCircuit[block] = std::move(compoundOp);
}
for (auto i : bitBlocks[block]) {
// need to make a copy here because otherwise the updates in the loop might
// invalidate the iterator
const auto blockBits = bitBlocks[block];
for (auto i : blockBits) {
parent[i] = i;
bitBlocks[i] = {i};
currentBlockInCircuit[i] = nullptr;
Expand Down

0 comments on commit cefedf2

Please sign in to comment.