CallGraphSCCPass

I’m building a SCCPass below, it appears that the CallGraphNode->getFunction returns a valid function but seg faults on call like “getName” or “size” but not on calls like “empty” (which returns false).

My understanding is that the heirarchy is: CallGraphSCC->CallGraphNode->Function->BasicBlock->Instruction, is this not the case?

virtual bool runOnSCC(CallGraphSCC &SCC) {
errs() << “CDFGPass: " << “\n”;
errs() <<“Size of SCC: “<<SCC.size()<<”\n”;
for(CallGraphSCC::iterator CGNodeItr = SCC.begin(); CGNodeItr != SCC.end();++CGNodeItr)
{
errs()<<“Iterating CallNodeGraphs”<<”\n";
const CallGraphNode *CGNode = cast(&CGNodeItr);
errs()<<“Getting Function”<<"\n";
F = CGNode->getFunction();
if (F) {
errs()<<“function is good”<<"\n"; }
if (F->empty()) {
errs()<<“function is empty”<<"\n"; }
else {
errs()<<“basic blocks in function”<<"\n";
size_t F_size = F->size(); }
for(Function::iterator BBitr=F->begin(); BBitr!=F->end(); ++BBitr)
{
errs()<<“basic block begin”<<"\n";
const BasicBlock
BB = cast(&*BBitr);
errs()<<“basic block end”<<"\n";
}
errs()<<*CGNodeItr<<"\n";
errs()<<“Loop Back to Call Graph Node”<<"\n";
}
errs()<<“END”<<"\n";
return false;
}

Hi Ryan,

                 const CallGraphNode *CGNode = cast<CallGraphNode>(&*CGNodeItr);

does this work better:
   CallGraphNode *CGNode = *CGNodeItr;
?

It looks to me like &*CGNodeItr is a CallGraphNode** not a CallGraphNode*.

Ciao, Duncan.