[LLVMdev] Trouble traversing the CallGraph

Gabriel Rodríguez grodriguez at udc.es
Wed Mar 30 07:51:39 PDT 2011


I am finding some weird behavior in the CallGraph, and am not sure what am I doing wrong. When trying to traverse nodes 
in the CallGraph I get stuck in nodes representing external functions. Take the following code: 

----- 
#include <stdio.h> 

int main() { 
printf( "Hello World!\n" ); 
} 
----- 

If I try to traverse the CallGraph using the following code: 

----- 
CallGraph CG = this->getAnalysis<CallGraph>(); 
for( CallGraph::const_iterator i = CG.begin(); i != CG.end(); ++i ) { 
CallGraphNode * cgn = i->second; 
for( CallGraphNode::const_iterator ii = cgn->begin(); 
ii != cgn->end(); ++ii ) {} 
} 
----- 

The CallGraphNode::const_iterator is inconsistent. For starters, the inner loop never exits and, besides, if I 
try to use the values contained in the iterator (e.g. ii->second) I get segfaults. Calling CG.dump() works 
flawlessly, but mimicking the code from CG.dump() in my user code produces inconsistent CGN iterators 
again. I am at a loss here, any ideas? 

Best, 
Gabriel 

PS: I have already added the CallGraph analysis to the pass requirements. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110330/44cffa22/attachment.html>


More information about the llvm-dev mailing list