LLVM在getAnalysis上传递段错误<dominatortree>()</dominatortree>

时间:2013-02-10 15:09:35

标签: segmentation-fault llvm

我正在尝试为LLVM 3.2优化器构建一个传递,我需要一个支配树。通过从PassManager请求DominatorTree分析结果可以很容易地实现这一点,但即使这个简单的例子也会崩溃。

我做错了什么?

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);

调用

opt --load mypass.so -mypass --debug-pass=Structure test.bc

它立即与

分段错误
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)

1 个答案:

答案 0 :(得分:3)

DominatorTree& DT = getAnalysis<DominatorTree>(F);更改为DominatorTree& DT = getAnalysis<DominatorTree>();似乎有效。