Hi, all:
I wanted to use a FunctionPass (e.g. MemoryDependenceAnalysis) in a ModulePass, and then I used the method “getAnalysis<MemoryDependenceAnalysis>(llvm::Function *)” described at http://llvm.org/docs/WritingAnLLVMPass.html#ModulePass to get the FunctionPass. But , it still crashed when I invoked this pass in tool ‘opt’.
However, if I change my pass to inherit from FunctionPass, then everything goes well. But I must use the ModulePass to solve my problem. What can I do now?
Following is the project file and crash infomation.
--------------------------------------part of my project file--------------------------------------------------------
struct pFuncName : public ModulePass {
…
virtual bool runOnModule(Module &M)
{
for(Module::iterator mib=M.begin(), mie=M.end(); mib!=mie; ++mib)
{
MemoryDependenceAnalysis &mda = getAnalysis(*f); // I have noticed
…
}
return false;
}
void getAnalysisUsage(AnalysisUsage &AU) const
{
AU.addRequired();
}
};
-----------------------------------------------crash infomation----------------------------------------------------
$ opt -load /home//llvm-2.5/Debug/lib/g_pFuncName.so -g_pFuncName < test.bc > /dev/null
_opt: /home//llvm-2.5/include/llvm/Target/TargetData.h:114: llvm::TargetData::TargetData(): Assertion `0 && "ERROR: Bad TargetData ctor used. " “Tool did not specify a TargetData to use?”’ failed._
0 opt 0x08604986
1 opt 0x08604cc8
2 0x003ba400 __kernel_sigreturn + 0
3 libc.so.6 0x009cce28 abort + 392
4 libc.so.6 0x009c440e __assert_fail + 238
5 opt 0x08507bc5 llvm::Pass* llvm::callDefaultCtorllvm::TargetData() + 0
6 opt 0x08507be2 llvm::Pass* llvm::callDefaultCtorllvm::TargetData() + 29
7 opt 0x08596996 llvm::PassInfo::createPass() const + 126
8 opt 0x0859156a llvm::PMTopLevelManager::schedulePass(llvm::Pass*) + 284
9 opt 0x085915f1 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) + 419
10 opt 0x0859b9ec llvm::FunctionPassManagerImpl::add(llvm::Pass*) + 30
11 opt 0x085917ab llvm::MPPassManager::addLowerLevelRequiredPass(llvm::Pass*, llvm::Pass*) + 315
12 opt 0x08592636 llvm::PMDataManager::add(llvm::Pass*, bool) + 816
13 opt 0x08592a81 llvm::ModulePass::assignPassManager(llvm::PMStack&, llvm::PassManagerType) + 137
14 opt 0x0859b8a9 llvm::PassManagerImpl::addTopLevelPass(llvm::Pass*) + 237
15 opt 0x08591642 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) + 500
16 opt 0x0859b9cc llvm::PassManagerImpl::add(llvm::Pass*) + 30
17 opt 0x08591667 llvm::PassManager::add(llvm::Pass*) + 27
18 opt 0x082d10c2
19 opt 0x082d2f03 main + 3181
20 libc.so.6 0x009b66e5 __libc_start_main + 229
21 opt 0x082c4641
Aborted (core dumped)