From f313ed5b7bc247374764589ae2025012d5c43dd5 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Wed, 12 Dec 2018 17:22:52 +0000 Subject: [PATCH] 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 llvm-svn: 348942 --- clang/include/clang/Analysis/CallGraph.h | 1 + .../{debug-CallGraph.c => debug-CallGraph.cpp} | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) rename clang/test/Analysis/{debug-CallGraph.c => debug-CallGraph.cpp} (79%) diff --git a/clang/include/clang/Analysis/CallGraph.h b/clang/include/clang/Analysis/CallGraph.h index ae0f392..e230930 100644 --- a/clang/include/clang/Analysis/CallGraph.h +++ b/clang/include/clang/Analysis/CallGraph.h @@ -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. diff --git a/clang/test/Analysis/debug-CallGraph.c b/clang/test/Analysis/debug-CallGraph.cpp similarity index 79% rename from clang/test/Analysis/debug-CallGraph.c rename to clang/test/Analysis/debug-CallGraph.cpp index 9f3865b..7f9ee4d 100644 --- a/clang/test/Analysis/debug-CallGraph.c +++ b/clang/test/Analysis/debug-CallGraph.cpp @@ -51,8 +51,27 @@ void test_single_call() { do_nothing(); } +template +void templ(T t) { + ccc(); +} + +template<> +void templ(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 $}} -- 2.7.4