diff options
| author | Owen Anderson <resistor@mac.com> | 2008-02-05 04:34:03 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2008-02-05 04:34:03 +0000 |
| commit | 1de59971196f3558c3ac9183717e838c2ca70add (patch) | |
| tree | bff5c715c534a534ec146d879d3512f3ff856d77 /llvm/lib/Analysis | |
| parent | 6c037da51ca1c8518f0bfaa93d6d78babbefd51b (diff) | |
| download | bcm5719-llvm-1de59971196f3558c3ac9183717e838c2ca70add.tar.gz bcm5719-llvm-1de59971196f3558c3ac9183717e838c2ca70add.zip | |
Fix an obscure read-after-free bug that Duncan found.
llvm-svn: 46738
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp index 445e16dbb31..60e9e6b9e4b 100644 --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -463,15 +463,17 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) { 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 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* 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); - } + } 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); |

