aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/MemoryDependenceAnalysis.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-02-05 04:34:03 +0000
committerOwen Anderson <resistor@mac.com>2008-02-05 04:34:03 +0000
commita8701a6c62158b2b84cc24ed2149e4107d03409a (patch)
treefdd1166f57014a81508e62ea46d424b3f1d4a21e /lib/Analysis/MemoryDependenceAnalysis.cpp
parent131d5c9f4a33a86464432ac194459217cca73c6e (diff)
downloadexternal_llvm-a8701a6c62158b2b84cc24ed2149e4107d03409a.zip
external_llvm-a8701a6c62158b2b84cc24ed2149e4107d03409a.tar.gz
external_llvm-a8701a6c62158b2b84cc24ed2149e4107d03409a.tar.bz2
Fix an obscure read-after-free bug that Duncan found.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46738 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemoryDependenceAnalysis.cpp')
-rw-r--r--lib/Analysis/MemoryDependenceAnalysis.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp
index 445e16d..60e9e6b 100644
--- a/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/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);