]> granicus.if.org Git - clang/commitdiff
Make clang::CallGraph look into template instantiations
authorErich Keane <erich.keane@intel.com>
Wed, 12 Dec 2018 17:22:52 +0000 (17:22 +0000)
committerErich Keane <erich.keane@intel.com>
Wed, 12 Dec 2018 17:22:52 +0000 (17:22 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348942 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/CallGraph.h
test/Analysis/debug-CallGraph.cpp [moved from test/Analysis/debug-CallGraph.c with 79% similarity]

index ae0f392ed9697b0a705689ae0736eead7989a5c6..e230930b59e0f5ad1ff649c90642ee6d672174ff 100644 (file)
@@ -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.
similarity index 79%
rename from test/Analysis/debug-CallGraph.c
rename to test/Analysis/debug-CallGraph.cpp
index 9f3865b35a4ea765801cae3fb6c80999e7c688ad..7f9ee4dc94fd086a35a9864c4cb63a1cb1ee4017 100644 (file)
@@ -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 $}}