diff options
author | 2015-09-17 15:47:05 +0100 | |
---|---|---|
committer | 2015-09-17 16:06:59 +0100 | |
commit | b7d8e8cf7063fdec1cce6ebd33e33804976bd978 (patch) | |
tree | 8d60856999139cf5b0b0f145f69c35a84a60716c /compiler/optimizing/nodes.cc | |
parent | a201d5eeb0903408df925a1ed1686a55238a274c (diff) |
Optimizing: Do not use range-based loop when inserting elements.
When we iterate over the elements of a container and we may
insert new elements into that container, it's wrong to use
the range-based loop.
Bug: 24133462
Change-Id: Iee35fbcf88ed3bcd6155cbeba09bd256032a16be
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r-- | compiler/optimizing/nodes.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 54f4071e22..b2407c520c 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -289,7 +289,10 @@ static bool CheckIfPredecessorAtIsExceptional(const HBasicBlock& block, size_t p } void HGraph::SimplifyCatchBlocks() { - for (HBasicBlock* catch_block : blocks_) { + // NOTE: We're appending new blocks inside the loop, so we need to use index because iterators + // can be invalidated. We remember the initial size to avoid iterating over the new blocks. + for (size_t block_id = 0u, end = blocks_.size(); block_id != end; ++block_id) { + HBasicBlock* catch_block = blocks_[block_id]; if (!catch_block->IsCatchBlock()) { continue; } @@ -349,7 +352,10 @@ void HGraph::SimplifyCFG() { // Simplify the CFG for future analysis, and code generation: // (1): Split critical edges. // (2): Simplify loops by having only one back edge, and one preheader. - for (HBasicBlock* block : blocks_) { + // NOTE: We're appending new blocks inside the loop, so we need to use index because iterators + // can be invalidated. We remember the initial size to avoid iterating over the new blocks. + for (size_t block_id = 0u, end = blocks_.size(); block_id != end; ++block_id) { + HBasicBlock* block = blocks_[block_id]; if (block == nullptr) continue; if (block->NumberOfNormalSuccessors() > 1) { for (size_t j = 0; j < block->GetSuccessors().size(); ++j) { |