When comparing DominanceFrontier's, advance iterators
authorDuncan Sands <baldrick@free.fr>
Wed, 20 May 2009 15:12:01 +0000 (15:12 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 20 May 2009 15:12:01 +0000 (15:12 +0000)
before erasing nodes, not after.  Otherwise dom frontier
checking reads from freed memory.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72168 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Dominators.h

index 35cdb246518dd2dc67239d5d3a2913938e120bb4..0bb98ec6a887e7f80a743b00bdf016d011779b7e 100644 (file)
@@ -968,8 +968,8 @@ public:
       tmpSet.insert(*I);
 
     for (DomSetType::const_iterator I = DS1.begin(),
-           E = DS1.end(); I != E; ++I) {
-      BasicBlock *Node = *I;
+           E = DS1.end(); I != E; ) {
+      BasicBlock *Node = *I++;
 
       if (tmpSet.erase(Node) == 0)
         // Node is in DS1 but not in DS2.
@@ -993,7 +993,7 @@ public:
       tmpFrontiers.insert(std::make_pair(I->first, I->second));
 
     for (DomSetMapType::iterator I = tmpFrontiers.begin(),
-           E = tmpFrontiers.end(); I != E; ++I) {
+           E = tmpFrontiers.end(); I != E; ) {
       BasicBlock *Node = I->first;
       const_iterator DFI = find(Node);
       if (DFI == end()) 
@@ -1002,6 +1002,7 @@ public:
       if (compareDomSet(I->second, DFI->second))
         return true;
 
+      ++I;
       tmpFrontiers.erase(Node);
     }