2.9 pass manager asserts "Unable to handle Pass that requires lower level Analysis pass"

Hi,

I am trying to write an LLVM project, using LLVM 2.9. My passes are defined as follows, where the Pass2 requires Pass1.

namespace llvm {

class BaseClass : public ModulePass {
// Name for printing
const char* printname;
protected:
BaseClass(char id, const char* name)
: ModulePass(id),printname(name){
}
};

class Pass1 : public BaseClass {
public:
static char ID;
Pass1() : BaseClass(ID, “pass1”) { }
~Pass1() { releaseMemory(); }
virtual bool runOnModule(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
};
class Pass2 : public BaseClass {
public:
static char ID;
Pass2() : BaseClass(ID, “pass2”) { }
~Pass2() { releaseMemory(); }

virtual bool runOnModule(Module &M);

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired();
AU.setPreservesAll();
}
};
} // End llvm namespace

The passes are registered as follows

using namespace llvm;
RegisterPass
X(“pass1”, “Phase1”);
char Pass1::ID = 0;

bool Pass1::runOnModule(Module &M) {
M.dump();
return false;
}

static RegisterPass
Y(“pass2”, “Phase 2”);
char Pass2::ID = 0;

bool Pass2::runOnModule (Module &M) {
M.dump();
return false;
}

I hit the following assert
opt: /home/vadve/aggarwa4/llvm29/llvm-2.9/lib/VMCore/PassManager.cpp:1613: virtual void llvm::MPPassManager::addLowerLevelRequiredPass(llvm::Pass*, llvm::Pass*): Assertion `(P->getPotentialPassManagerType() < RequiredPass->getPotentialPassManagerType()) && “Unable to handle Pass that requires lower level Analysis pass”’ failed.

It works fine if I have pass2 require a different modulePass. But fails when the two module passes share the common parent class.

Any pointers on whether the code is wrong, or if this is not the right way to do this, would be great.

Thanks,
Arushi