I'm trying to build a pass for the LLVM 3.2 optimizer where I need a dominator tree. This should easily be possible by requesting the DominatorTree
analysis result from the PassManager, but even this simple example crashes.
What am I doing wrong?
namespace {
struct Mypass : public FunctionPass {
static char ID;
Mypass() : FunctionPass(ID) { }
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<DominatorTree>();
}
virtual bool runOnFunction(Function &F) {
DominatorTree& DT = getAnalysis<DominatorTree>(F);
return false;
}
};
}
char Mypass::ID = 0;
static RegisterPass<Mypass> X("mypass", "My test analysis", true, true);
when called with
opt --load mypass.so -mypass --debug-pass=Structure test.bc
it immediately segfaults with
Pass Arguments: -targetlibinfo -datalayout -domtree -mypass -preverify -domtree -verify
Target Library Information
Data Layout
ModulePass Manager
FunctionPass Manager
Dominator Tree Construction
My test analysis
Preliminary module verification
Dominator Tree Construction
Module Verifier
0 libLLVM-3.2.so.1 0x00007f2d8172a1df
1 libLLVM-3.2.so.1 0x00007f2d8172a649
2 libpthread.so.0 0x00007f2d80842bd0
3 mypass.so 0x00007f2d7f63deb9 llvm::DominatorTree& llvm::Pass::getAnalysisID<llvm::DominatorTree>(void const*, llvm::Function&) + 217
4 mypass.so 0x00007f2d7f63ddce llvm::DominatorTree& llvm::Pass::getAnalysis<llvm::DominatorTree>(llvm::Function&) + 94
5 mypass.so 0x00007f2d7f63dc38
6 libLLVM-3.2.so.1 0x00007f2d811e0e3f llvm::FPPassManager::runOnFunction(llvm::Function&) + 575
7 libLLVM-3.2.so.1 0x00007f2d811e0e83 llvm::FPPassManager::runOnModule(llvm::Module&) + 51
8 libLLVM-3.2.so.1 0x00007f2d811e0ba4 llvm::MPPassManager::runOnModule(llvm::Module&) + 484
9 libLLVM-3.2.so.1 0x00007f2d811e44bb llvm::PassManagerImpl::run(llvm::Module&) + 107
10 opt 0x000000000040d606 main + 4230
11 libc.so.6 0x00007f2d80189ea5 __libc_start_main + 245
12 opt 0x000000000040db41
Stack dump:
0. Program arguments: opt --load mypass.so -mypass --debug-pass=Structure
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'My test analysis' on function '@const_expr'
Segmentation fault (core dumped)
Change DominatorTree& DT = getAnalysis<DominatorTree>(F);
to DominatorTree& DT = getAnalysis<DominatorTree>();
seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With