[llvm-dev] Error while iterating over callee nodes in CallGraph

Niddodi, Chaitra via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 15 12:25:20 PST 2019


Hello,

I've written a Module Pass to iterate over the CallGraph using the CallGraph Pass. Here is the code for getAnalysisUsage and runOnModule methods:

    void getAnalysisUsage(AnalysisUsage &AU) const {
  AU.addRequired<CallGraph>();
  AU.addPreserved<CallGraph>();
  }

    bool runOnModule(Module &M) override {
CallGraph &cg = getAnalysis<CallGraph>();
  CallGraphNode *cgm = cg[M.getFunction("main")];

  for (CallGraphNode::iterator ti = cgm->begin(); ti != cgm->end(); ++ti)
     {
      CallGraphNode * cgn = ti->second;
      if(cgn==NULL)
        continue;
      errs()<<cgn->getFunction()<<"\n";
      errs()<<cgn->getFunction()->getName()<<"\n";
    }
      return false;
    }


I'm using llvm3.4.2 to compile and run the pass. I get the following error while iterating through callee nodes of main function:

0  opt             0x00000000011d2302 llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1  opt             0x00000000011d1eb4
2  libpthread.so.0 0x00007f88d72d3330
3  libcgwalk.so     0x00007f88d64d6596
4  opt             0x00000000010ddb45 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 709
5  opt             0x0000000000552724 main + 2452
6  libc.so.6       0x00007f88d66fbf45 __libc_start_main + 245
7  opt             0x000000000056d865
Stack dump:
0. Program arguments: opt -load build/proj/libcgwalk.so -cgwalk
1. Running pass 'Cgwalk' on module '<stdin>'.
Segmentation fault (core dumped)


I'm running the pass on bitcode of a simple C program where main calls 2 other functions.

Thanks,
Chaitra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191215/e9d36951/attachment.html>


More information about the llvm-dev mailing list