CallGraphNode giving incorrect function Name

Hi,

I am trying to traverse the call graph. Once I get a node in the call graph, I am trying to print the function name corresponding to that call graph node as well as the number of references.

Results:

1)The function name is always an empty string.

2)The number of references is always a random number.

3)Also the called functions names are also an empty string.

Code:
bool runOnModule(llvm::Module &M) override
{

CallGraph cg = CallGraph(M);
cg.dump();// this is correct. It is printing the expected the call graph

for ( CallGraph::const_iterator itr = cg.begin(), ie = cg.end() ; itr != ie; itr++)
{
if (itr->second != nullptr)
{
itr->second->dump();
errs()<<"-----------CGN---------\n";
CallGraphNode *cgn = itr->second.get();

if(const Function* fptr = cgn->getFunction())
{
errs()<<“Number of references are”<getNumReferences()<<"\n";

errs()<getName()<<"\n";

if(cgn->operator != nullptr)
{

if(cgn->operator->getFunction() != nullptr)
{
errs()<operator->getFunction()->getName()<<"\n";
}

}
}
}
}
}