diff options
Diffstat (limited to 'compilerplugins/clang/unusedmethods.cxx')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 7dc57e9b88c7..28683347fa1d 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -137,18 +137,25 @@ static bool isStandardStuff(const std::string& s) || startsWith(s, "(anonymous namespace)::"); } +// prevent recursive templates from blowing up the stack +static std::set<std::string> traversedTemplateFunctionSet; + bool UnusedMethods::VisitCallExpr(CallExpr* expr) { if (ignoreLocation(expr)) { return true; } FunctionDecl* calleeFunctionDecl = expr->getDirectCallee(); - // if we see a call to a templated method, it effectively instantiates a new method, - // so we need to examine it's interior to see if it in turn calls anything else - if (calleeFunctionDecl->getTemplatedKind() != clang::FunctionDecl::TemplatedKind::TK_NonTemplate + 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()) { - TraverseFunctionDecl(calleeFunctionDecl); + if (traversedTemplateFunctionSet.insert(calleeFunctionDecl->getQualifiedNameAsString()).second) + TraverseFunctionDecl(calleeFunctionDecl); } CXXMethodDecl* calleeMethodDecl = dyn_cast_or_null<CXXMethodDecl>(calleeFunctionDecl); |