Niddodi, Chaitra via llvm-dev
2019-Dec-15 20:25 UTC
[llvm-dev] Error while iterating over callee nodes in CallGraph
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>
Doerfert, Johannes via llvm-dev
2019-Dec-16 02:38 UTC
[llvm-dev] Error while iterating over callee nodes in CallGraph
On 12/15, Niddodi, Chaitra via llvm-dev wrote:> 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";I think the function (cgn->getFunction()) can be NULL (to indicate special edges). Make sure it isn't. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 228 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191216/d168cc76/attachment.sig>