summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Ristow <warren_ristow@playstation.sony.com>2020-01-14 10:30:24 -0800
committerWarren Ristow <warren_ristow@playstation.sony.com>2020-01-14 10:30:24 -0800
commitf7e9f4f4c50245d10ca9869a9f8f3d431dfb6948 (patch)
treea4f008954d9302b065f53655b314871a08cfc2ef
parenteb23cc136b68b24e63dd765b87d1facecd622695 (diff)
downloadbcm5719-llvm-f7e9f4f4c50245d10ca9869a9f8f3d431dfb6948.tar.gz
bcm5719-llvm-f7e9f4f4c50245d10ca9869a9f8f3d431dfb6948.zip
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
-rw-r--r--llvm/include/llvm/ADT/SCCIterator.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h
index eb1a5d0938c..1e642b9f75d 100644
--- a/llvm/include/llvm/ADT/SCCIterator.h
+++ b/llvm/include/llvm/ADT/SCCIterator.h
@@ -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);
}
};
OpenPOWER on IntegriCloud