[CallGraph] Make sure the edges are not missed due to re-declarations

A patch by Daniel DeFreez!

We were previously dropping edges on re-declarations. Store the
canonical declarations in the graph to ensure that different
references to the same function end up reflected with the same call graph
node.

(Note, this might lead to performance fluctuation because call graph
is used to determine the function analysis order.)

llvm-svn: 224398
This commit is contained in:
Anna Zaks 2014-12-17 00:34:07 +00:00
parent 04b69f89aa
commit 87d404d458
2 changed files with 22 additions and 14 deletions

View File

@ -110,14 +110,13 @@ CallGraph::~CallGraph() {
bool CallGraph::includeInGraph(const Decl *D) {
assert(D);
if (!D->getBody())
if (!D->hasBody())
return false;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// We skip function template definitions, as their semantics is
// only determined when they are instantiated.
if (!FD->isThisDeclarationADefinition() ||
FD->isDependentContext())
if (FD->isDependentContext())
return false;
IdentifierInfo *II = FD->getIdentifier();
@ -125,11 +124,6 @@ bool CallGraph::includeInGraph(const Decl *D) {
return false;
}
if (const ObjCMethodDecl *ID = dyn_cast<ObjCMethodDecl>(D)) {
if (!ID->isThisDeclarationADefinition())
return false;
}
return true;
}
@ -152,6 +146,9 @@ CallGraphNode *CallGraph::getNode(const Decl *F) const {
}
CallGraphNode *CallGraph::getOrInsertNode(Decl *F) {
if (F && !isa<ObjCMethodDecl>(F))
F = F->getCanonicalDecl();
CallGraphNode *&Node = FunctionMap[F];
if (Node)
return Node;

View File

@ -23,11 +23,22 @@ void bbb(int y) {
foo(x, y);
}();
}
void ccc();
void ddd() { ccc(); }
void ccc() {}
void eee();
void eee() {}
void fff() { eee(); }
// CHECK:--- Call graph Dump ---
// CHECK: Function: < root > calls: mmm foo aaa < > bbb
// CHECK: Function: bbb calls: < >
// CHECK: Function: < > calls: foo
// CHECK: Function: aaa calls: foo
// CHECK: Function: foo calls: mmm
// CHECK: Function: mmm calls:
// CHECK-NEXT: {{Function: < root > calls: mmm foo aaa < > bbb ccc ddd eee fff $}}
// CHECK-NEXT: {{Function: fff calls: eee $}}
// CHECK-NEXT: {{Function: eee calls: $}}
// CHECK-NEXT: {{Function: ddd calls: ccc $}}
// CHECK-NEXT: {{Function: ccc calls: $}}
// CHECK-NEXT: {{Function: bbb calls: < > $}}
// CHECK-NEXT: {{Function: < > calls: foo $}}
// CHECK-NEXT: {{Function: aaa calls: foo $}}
// CHECK-NEXT: {{Function: foo calls: mmm $}}
// CHECK-NEXT: {{Function: mmm calls: $}}