LLVM通过getAnalysis <DominatorTree>传递段错误()

我正在尝试为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)

更改DominatorTree& DT = getAnalysis<DominatorTree>(F);DominatorTree& DT = getAnalysis<DominatorTree>(); 似乎工作。

链接地址: http://www.djcxy.com/p/11779.html

上一篇: LLVM Pass segfaults on getAnalysis<DominatorTree>()

下一篇: Xcode 4.6 Strange issues with Debugger."po" command does not work