[llvm-commits] [llvm] r46738 - /llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Owen Anderson resistor at mac.com
Mon Feb 4 20:34:04 PST 2008


Author: resistor
Date: Mon Feb  4 22:34:03 2008
New Revision: 46738

URL: http://llvm.org/viewvc/llvm-project?rev=46738&view=rev
Log:
Fix an obscure read-after-free bug that Duncan found.

Modified:
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=46738&r1=46737&r2=46738&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Mon Feb  4 22:34:03 2008
@@ -463,15 +463,17 @@
     reverseDep[depGraphLocal[rem].first].erase(rem);
     
     if (depGraphEntry->second.first != NonLocal &&
+        depGraphEntry->second.first != None &&
         depGraphEntry->second.second) {
       // If we have dep info for rem, set them to it
       BasicBlock::iterator RI = depGraphEntry->second.first;
       RI++;
       newDep = RI;
-    } else if (depGraphEntry->second.first == NonLocal &&
+    } else if ( (depGraphEntry->second.first == NonLocal ||
+                 depGraphEntry->second.first == None ) &&
                depGraphEntry->second.second ) {
       // If we have a confirmed non-local flag, use it
-      newDep = NonLocal;
+      newDep = depGraphEntry->second.first;
     } else {
       // Otherwise, use the immediate successor of rem
       // NOTE: This is because, when getDependence is called, it will first
@@ -480,14 +482,22 @@
       RI++;
       newDep = RI;
     }
-    
-    SmallPtrSet<Instruction*, 4>& set = reverseDep[rem];
-    for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
-         I != E; ++I) {
-      // Insert the new dependencies
-      // Mark it as unconfirmed as long as it is not the non-local flag
-      depGraphLocal[*I] = std::make_pair(newDep, !newDep);
-    }
+  } else {
+    // Otherwise, use the immediate successor of rem
+    // NOTE: This is because, when getDependence is called, it will first
+    // check the immediate predecessor of what is in the cache.
+    BasicBlock::iterator RI = rem;
+    RI++;
+    newDep = RI;
+  }
+  
+  SmallPtrSet<Instruction*, 4>& set = reverseDep[rem];
+  for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
+       I != E; ++I) {
+    // Insert the new dependencies
+    // Mark it as unconfirmed as long as it is not the non-local flag
+    depGraphLocal[*I] = std::make_pair(newDep, (newDep == NonLocal ||
+                                                newDep == None));
   }
   
   depGraphLocal.erase(rem);





More information about the llvm-commits mailing list