aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/LegacyPassManager.cpp
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2014-04-08 03:40:34 +0000
committerAndrew Trick <atrick@apple.com>2014-04-08 03:40:34 +0000
commit02066f2a4d277b62943177762a29d34d0f5072dc (patch)
tree45405ea772cba9a2653f4c3d59a8af97cd9c679f /llvm/lib/IR/LegacyPassManager.cpp
parentc9d26255868969e6a962abbfbc0180dd75b47eb8 (diff)
downloadllvm-02066f2a4d277b62943177762a29d34d0f5072dc.zip
llvm-02066f2a4d277b62943177762a29d34d0f5072dc.tar.gz
llvm-02066f2a4d277b62943177762a29d34d0f5072dc.tar.bz2
Fix a (legacy) PassManager crash that occurs when a ModulePass
indirectly requires a function analysis. This bug was reported by Jason Kim. He included a test case here: http://reviews.llvm.org/D3312 llvm-svn: 205753
Diffstat (limited to 'llvm/lib/IR/LegacyPassManager.cpp')
-rw-r--r--llvm/lib/IR/LegacyPassManager.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index 7c5cc68..ab5281b 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -1657,6 +1657,8 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
assert((P->getPotentialPassManagerType() <
RequiredPass->getPotentialPassManagerType()) &&
"Unable to handle Pass that requires lower level Analysis pass");
+ if (!RequiredPass)
+ return;
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
if (!FPP) {
@@ -1666,14 +1668,24 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
OnTheFlyManagers[P] = FPP;
}
- FPP->add(RequiredPass);
+ const PassInfo * RequiredPassPI =
+ PassRegistry::getPassRegistry()->getPassInfo(RequiredPass->getPassID());
- // Register P as the last user of RequiredPass.
- if (RequiredPass) {
- SmallVector<Pass *, 1> LU;
- LU.push_back(RequiredPass);
- FPP->setLastUser(LU, P);
+ Pass *FoundPass = NULL;
+ if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
+ FoundPass =
+ ((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID());
+ }
+ if (!FoundPass) {
+ FoundPass = RequiredPass;
+ // This should be guaranteed to add RequiredPass to the passmanager given
+ // that we checked for an avaiable analysis above.
+ FPP->add(RequiredPass);
}
+ // Register P as the last user of FoundPass or RequiredPass.
+ SmallVector<Pass *, 1> LU;
+ LU.push_back(FoundPass);
+ FPP->setLastUser(LU, P);
}
/// Return function pass corresponding to PassInfo PI, that is