forked from OSchip/llvm-project
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:
parent
eb23cc136b
commit
f7e9f4f4c5
|
@ -134,7 +134,10 @@ public:
|
||||||
/// has been deleted, and \c New is to be used in its place.
|
/// has been deleted, and \c New is to be used in its place.
|
||||||
void ReplaceNode(NodeRef Old, NodeRef New) {
|
void ReplaceNode(NodeRef Old, NodeRef New) {
|
||||||
assert(nodeVisitNumbers.count(Old) && "Old not in scc_iterator?");
|
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);
|
nodeVisitNumbers.erase(Old);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue