r295644 - [analyzer] Do not duplicate call graph nodes for functions that have definition and forward declaration

Aleksei Sidorin via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 01:16:48 PST 2017


Author: a.sidorin
Date: Mon Feb 20 03:16:48 2017
New Revision: 295644

URL: http://llvm.org/viewvc/llvm-project?rev=295644&view=rev
Log:
[analyzer] Do not duplicate call graph nodes for functions that have definition and forward declaration

Patch by Ivan Sidorenko!

Differential Revision: https://reviews.llvm.org/D29643

Modified:
    cfe/trunk/include/clang/Analysis/CallGraph.h
    cfe/trunk/test/Analysis/debug-CallGraph.c

Modified: cfe/trunk/include/clang/Analysis/CallGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CallGraph.h?rev=295644&r1=295643&r2=295644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CallGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/CallGraph.h Mon Feb 20 03:16:48 2017
@@ -98,7 +98,7 @@ public:
   bool VisitFunctionDecl(FunctionDecl *FD) {
     // We skip function template definitions, as their semantics is
     // only determined when they are instantiated.
-    if (includeInGraph(FD)) {
+    if (includeInGraph(FD) && FD->isThisDeclarationADefinition()) {
       // Add all blocks declared inside this function to the graph.
       addNodesForBlocks(FD);
       // If this function has external linkage, anything could call it.

Modified: cfe/trunk/test/Analysis/debug-CallGraph.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.c?rev=295644&r1=295643&r2=295644&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/debug-CallGraph.c (original)
+++ cfe/trunk/test/Analysis/debug-CallGraph.c Mon Feb 20 03:16:48 2017
@@ -43,8 +43,18 @@ void eee();
 void eee() {}
 void fff() { eee(); }
 
+// This test case tests that forward declaration for the top-level function
+// does not affect call graph construction.
+void do_nothing() {}
+void test_single_call();
+void test_single_call() {
+  do_nothing();
+}
+
 // CHECK:--- Call graph Dump ---
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ccc ddd eee fff $}}
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call $}}
+// CHECK-NEXT: {{Function: test_single_call calls: do_nothing $}}
+// CHECK-NEXT: {{Function: do_nothing calls: $}}
 // CHECK-NEXT: {{Function: fff calls: eee $}}
 // CHECK-NEXT: {{Function: eee calls: $}}
 // CHECK-NEXT: {{Function: ddd calls: ccc $}}




More information about the cfe-commits mailing list