Inconsistent result with CallGraph


We are working with LLVM-3.1 and we have a problem.This is the code we have executed:

virtual void getAnalysisUsage( llvm::AnalysisUsage & info ) const {



virtual bool runOnModule( Module & M )


CallGraph &CG = this->getAnalysis();

CallGraphNode *cgn;

unsigned nref;

for(CallGraph::const_iterator I=CG.begin(),E=CG.end();I!=E;I++)











In a simple program with only one function (Main), this is the output:


Call graph node for function: ‘main’<<0x7f928340c760>> #uses=1

We have been searching in llvm files and dump function calls getNumReferences() (which is in Callgraph.h). And it is assumed that the call cgn->getNumReferences() references to the same function. Why are we getting different values? Dump shows uses=1, and cgn->getNumReferences() shows uses=0;

We are writing a Module pass as you can see in the previous code. We have this pass registered as:

char PARALLWARE::ID = 0;

static RegisterPass X( “parallware”,“run Parallware source to source autoparallel compiler”);

Is this a bug or we are making a mistake?

Thank you for your time. Best regards

Hi Eugenio, I took a quick look at the 3.2 code and as far as I can see it is
impossible to get what you get. So I suggest you try running under valgrind
to see if you are using freed memory or something like that.

Ciao, Duncan.