-->

Segmentation fault while using AAResultsWrapperPas

2019-06-09 06:18发布

问题:

I am trying to migrate my project from llvm3.6.2 to llvm3.8.1. In my code, I have used AliasAnalysis and I am changing my code as follows:

#if defined(DDP_LLVM_VERSION_3_8)
AU.addRequired<AAResultsWrapperPass>();
#else
AU.addRequired<AliasAnalysis>();
#endif

And I am passing AliasAnalysis to the function as follow:

#if defined(DDP_LLVM_VERSION_3_8)
foo(*F,getAnalysis<AAResultsWrapperPass>().getAAResults());
#else
foo(*F,getAnalysis<AliasAnalysis>());
#endif

Function declaration is as follow:

void foo(Function &F, AliasAnalysis &AA);

This code is getting compiled properly. But when I run this, I am getting following errors.

#0 0x0000000001558e19 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/llvm/llvm-3.8/llvm-3.8.1.src/lib/Support/Unix/Signals.inc:322:0
#1 0x0000000001559195 PrintStackTraceSignalHandler(void*) /home/llvm/llvm-3.8/llvm-3.8.1.src/lib/Support/Unix/Signals.inc:380:0
#2 0x00000000015578f6 llvm::sys::RunSignalHandlers() /home/llvm/llvm-3.8/llvm-3.8.1.src/lib/Support/Signals.cpp:44:0
#3 0x000000000155891d SignalHandler(int) /home/llvm/llvm-3.8/llvm-3.8.1.src/lib/Support/Unix/Signals.inc:210:0
#4 0x00007f7d30b5b370 __restore_rt (/lib64/libpthread.so.0+0xf370)
#5 0x0000000000b04251 llvm::AAResultsWrapperPass& llvm::Pass::getAnalysisID<llvm::AAResultsWrapperPass>(void const*) const /home/llvm/llvm-3.8/install/include/llvm/PassAnalysisSupport.h:242:0
#6 0x0000000000b04251 llvm::AAResultsWrapperPass& llvm::Pass::getAnalysis<llvm::AAResultsWrapperPass>() const /home/llvm/llvm-3.8/install/include/llvm/PassAnalysisSupport.h:223:0

回答1:

I was calling getAnalysis<AAResultsWrapperPass>().getAAResults() from a module pass. Passing current function as argument to this function solved the issue.

getAnalysis<AAResultsWrapperPass>().getAAResults() - NOT working getAnalysis<AAResultsWrapperPass>().getAAResults(F)- working