SCC: Allow ReplaceNode to safely support insertion

If scc_iterator::ReplaceNode is inserting a new entry in the map,
rather than replacing an existing entry, the possibility of growing
the map could cause a failure.  This change safely implements the
insertion.

Reviewed By: probinson

Differential Revision: https://reviews.llvm.org/D72469
This commit is contained in:
Warren Ristow 2020-01-14 10:30:24 -08:00
parent eb23cc136b
commit f7e9f4f4c5
1 changed files with 4 additions and 1 deletions

View File

@ -134,7 +134,10 @@ public:
/// has been deleted, and \c New is to be used in its place.
void ReplaceNode(NodeRef Old, NodeRef New) {
assert(nodeVisitNumbers.count(Old) && "Old not in scc_iterator?");
nodeVisitNumbers[New] = nodeVisitNumbers[Old];
// Do the assignment in two steps, in case 'New' is not yet in the map, and
// inserting it causes the map to grow.
auto tempVal = nodeVisitNumbers[Old];
nodeVisitNumbers[New] = tempVal;
nodeVisitNumbers.erase(Old);
}
};