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

Anna Zaks ganna at apple.com
Tue Dec 16 16:34:07 PST 2014


Author: zaks
Date: Tue Dec 16 18:34:07 2014
New Revision: 224398

URL: http://llvm.org/viewvc/llvm-project?rev=224398&view=rev
Log:
[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.)

Modified:
    cfe/trunk/lib/Analysis/CallGraph.cpp
    cfe/trunk/test/Analysis/debug-CallGraph.c

Modified: cfe/trunk/lib/Analysis/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=224398&r1=224397&r2=224398&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CallGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/CallGraph.cpp Tue Dec 16 18:34:07 2014
@@ -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 Dec
       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
 }
 
 CallGraphNode *CallGraph::getOrInsertNode(Decl *F) {
+  if (F && !isa<ObjCMethodDecl>(F))
+    F = F->getCanonicalDecl();
+
   CallGraphNode *&Node = FunctionMap[F];
   if (Node)
     return Node;

Modified: cfe/trunk/test/Analysis/debug-CallGraph.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.c?rev=224398&r1=224397&r2=224398&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/debug-CallGraph.c (original)
+++ cfe/trunk/test/Analysis/debug-CallGraph.c Tue Dec 16 18:34:07 2014
@@ -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: $}}





More information about the cfe-commits mailing list