diff options
author | Noel Grandin <noel@peralex.com> | 2015-07-13 13:31:13 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2015-07-14 09:43:57 +0200 |
commit | a04354ecb34216d7fb9868f701fd3ee2b70883c8 (patch) | |
tree | 67ec495f409ccf4bdc6e7808bb40795eb5cac429 /compilerplugins/clang/unusedmethods.cxx | |
parent | 1038d628b3ece37251e3900e7c4014393c13dc3b (diff) |
improve the unusedmethods plugin
to find stuff called from 2 levels+ inside template methods
Change-Id: I4ba308a992e64a091e5364b8aa89e44d6772dcb0
Diffstat (limited to 'compilerplugins/clang/unusedmethods.cxx')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 655dfe2c2855..162bff0189c5 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -33,7 +33,6 @@ to auto-remove the method declarations Note that the actual process may involve a fair amount of undoing, hand editing, and general messing around to get it to work :-) -TODO ignore calls from a method to itself, so we can eliminate unused recursive methods TODO deal with calls to superclass/member constructors from other constructors, so we can find unused constructors TODO need to handle places where the code takes the address of a method, that needs to count @@ -139,7 +138,7 @@ static bool isStandardStuff(const std::string& s) } // prevent recursive templates from blowing up the stack -static std::set<std::string> traversedTemplateFunctionSet; +static std::set<std::string> traversedFunctionSet; bool UnusedMethods::VisitCallExpr(CallExpr* expr) { @@ -150,14 +149,12 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr) if (calleeFunctionDecl == nullptr) { return true; } - // if we see a call to a templated function, it effectively creates new code, - // so we need to examine it's interior to see if it, in turn, calls anything else - if (calleeFunctionDecl->getTemplatedKind() != FunctionDecl::TemplatedKind::TK_NonTemplate - || calleeFunctionDecl->isFunctionTemplateSpecialization()) - { - if (traversedTemplateFunctionSet.insert(calleeFunctionDecl->getQualifiedNameAsString()).second) - TraverseFunctionDecl(calleeFunctionDecl); - } + // if we see a call to a function, it may effectively create new code, + // if the function is templated. However, if we are inside a template function, + // calling another function on the same template, the same problem occurs. + // Rather than tracking all of that, just traverse anything we have not already traversed. + if (traversedFunctionSet.insert(calleeFunctionDecl->getQualifiedNameAsString()).second) + TraverseFunctionDecl(calleeFunctionDecl); CXXMethodDecl* calleeMethodDecl = dyn_cast_or_null<CXXMethodDecl>(calleeFunctionDecl); if (calleeMethodDecl == nullptr) { |