r348942 - Make clang::CallGraph look into template instantiations

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 12 09:22:52 PST 2018


Author: erichkeane
Date: Wed Dec 12 09:22:52 2018
New Revision: 348942

URL: http://llvm.org/viewvc/llvm-project?rev=348942&view=rev
Log:
Make clang::CallGraph look into template instantiations

Clang's CallGraph analysis doesn't use the RecursiveASTVisitor's setting
togo into template instantiations.  The result is that anything wanting
to do call graph analysis ends up missing any template function calls.

Change-Id: Ib4af44ed59f15d43f37af91622a203146a3c3189

Added:
    cfe/trunk/test/Analysis/debug-CallGraph.cpp   (contents, props changed)
      - copied, changed from r348932, cfe/trunk/test/Analysis/debug-CallGraph.c
Removed:
    cfe/trunk/test/Analysis/debug-CallGraph.c
Modified:
    cfe/trunk/include/clang/Analysis/CallGraph.h

Modified: cfe/trunk/include/clang/Analysis/CallGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CallGraph.h?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CallGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/CallGraph.h Wed Dec 12 09:22:52 2018
@@ -131,6 +131,7 @@ public:
   bool TraverseStmt(Stmt *S) { return true; }
 
   bool shouldWalkTypesOfTypeLocs() const { return false; }
+  bool shouldVisitTemplateInstantiations() const { return true; }
 
 private:
   /// Add the given declaration to the call graph.

Removed: cfe/trunk/test/Analysis/debug-CallGraph.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.c?rev=348941&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/debug-CallGraph.c (original)
+++ cfe/trunk/test/Analysis/debug-CallGraph.c (removed)
@@ -1,69 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCallGraph %s -fblocks 2>&1 | FileCheck %s
-
-int get5() {
-  return 5;
-}
-
-int add(int val1, int val2) {
-  return val1 + val2;
-}
-
-int test_add() {
-  return add(10, get5());
-}
-
-static void mmm(int y) {
-  if (y != 0)
-      y++;
-  y = y/y;
-}
-
-static int foo(int x, int y) {
-    mmm(y);
-    if (x != 0)
-      x++;
-    return 5/x;
-}
-
-void aaa() {
-  foo(1,2);
-}
-
-void bbb(int y) {
-  int x = (y > 2);
-  ^ {
-      foo(x, y);
-  }();
-}
-void ccc();
-void ddd() { ccc(); }
-void ccc() {}
-
-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 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 $}}
-// 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: $}}
-// CHECK-NEXT: {{Function: test_add calls: add get5 $}}
-// CHECK-NEXT: {{Function: add calls: $}}
-// CHECK-NEXT: {{Function: get5 calls: $}}

Copied: cfe/trunk/test/Analysis/debug-CallGraph.cpp (from r348932, cfe/trunk/test/Analysis/debug-CallGraph.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.cpp?p2=cfe/trunk/test/Analysis/debug-CallGraph.cpp&p1=cfe/trunk/test/Analysis/debug-CallGraph.c&r1=348932&r2=348942&rev=348942&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/debug-CallGraph.c (original)
+++ cfe/trunk/test/Analysis/debug-CallGraph.cpp Wed Dec 12 09:22:52 2018
@@ -51,8 +51,27 @@ void test_single_call() {
   do_nothing();
 }
 
+template<typename T>
+void templ(T t) {
+  ccc();
+}
+
+template<>
+void templ<double>(double t) {
+  eee();
+}
+
+
+void templUser() {
+  templ(5);
+  templ(5.5);
+}
+
 // CHECK:--- Call graph Dump ---
-// 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: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call templ templ templUser $}}
+// CHECK-NEXT: {{Function: templUser calls: templ templ $}}
+// CHECK-NEXT: {{Function: templ calls: eee $}}
+// CHECK-NEXT: {{Function: templ calls: ccc $}}
 // CHECK-NEXT: {{Function: test_single_call calls: do_nothing $}}
 // CHECK-NEXT: {{Function: do_nothing calls: $}}
 // CHECK-NEXT: {{Function: fff calls: eee $}}

Propchange: cfe/trunk/test/Analysis/debug-CallGraph.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Analysis/debug-CallGraph.cpp
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Rev URL"

Propchange: cfe/trunk/test/Analysis/debug-CallGraph.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the cfe-commits mailing list