From: Anna Zaks Date: Wed, 17 Dec 2014 00:34:07 +0000 (+0000) Subject: [CallGraph] Make sure the edges are not missed due to re-declarations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=022f9458d99eef2f2fd4509058188c9e2f7aa1f5;p=clang [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.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224398 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index f41a96d30e..91a8492eaa 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -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(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(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(F)) + F = F->getCanonicalDecl(); + CallGraphNode *&Node = FunctionMap[F]; if (Node) return Node; diff --git a/test/Analysis/debug-CallGraph.c b/test/Analysis/debug-CallGraph.c index 4523c78935..64259e2069 100644 --- a/test/Analysis/debug-CallGraph.c +++ b/test/Analysis/debug-CallGraph.c @@ -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: $}}