summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-27 21:58:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-28 08:29:13 +0200
commitac50f685c7cf77fdc6ad9bac4030bfa82c5ce29b (patch)
tree3bd7ed41d6c78c59c9bf3c3c18ca97ec9a482f8a
parent7c548bf66af69a308ab891bc396cc192c9bf30c9 (diff)
loplugin:unusedmethods ignore recursive calls
Change-Id: I651a7bf0c705acc5580af8b7742d2d035ec64388
-rw-r--r--compilerplugins/clang/unusedmethods.cxx43
1 files changed, 42 insertions, 1 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index ef681f12c561..e33bb0c01c0a 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -115,12 +115,17 @@ public:
bool VisitDeclRefExpr( const DeclRefExpr* );
bool VisitCXXConstructExpr( const CXXConstructExpr* );
bool TraverseCXXRecordDecl( CXXRecordDecl* );
+ bool TraverseFunctionDecl( FunctionDecl* );
+ bool TraverseCXXMethodDecl( CXXMethodDecl* );
+ bool TraverseCXXConversionDecl( CXXConversionDecl* );
+ bool TraverseCXXDeductionGuideDecl( CXXDeductionGuideDecl* );
private:
void logCallToRootMethods(const FunctionDecl* functionDecl, std::set<MyFuncInfo>& funcSet);
MyFuncInfo niceName(const FunctionDecl* functionDecl);
std::string toString(SourceLocation loc);
void functionTouchedFromExpr( const FunctionDecl* calleeFunctionDecl, const Expr* expr );
CXXRecordDecl const * currentCxxRecordDecl = nullptr;
+ FunctionDecl const * currentFunctionDecl = nullptr;
};
MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
@@ -227,7 +232,10 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr)
}
gotfunc:
- logCallToRootMethods(calleeFunctionDecl, callSet);
+
+ // for "unused method" analysis, ignore recursive calls
+ if (currentFunctionDecl != calleeFunctionDecl)
+ logCallToRootMethods(calleeFunctionDecl, callSet);
const Stmt* parent = getParentStmt(expr);
@@ -356,6 +364,39 @@ bool UnusedMethods::TraverseCXXRecordDecl(CXXRecordDecl* cxxRecordDecl)
return ret;
}
+bool UnusedMethods::TraverseFunctionDecl(FunctionDecl* f)
+{
+ auto copy = currentFunctionDecl;
+ currentFunctionDecl = f;
+ bool ret = RecursiveASTVisitor::TraverseFunctionDecl(f);
+ currentFunctionDecl = copy;
+ return ret;
+}
+bool UnusedMethods::TraverseCXXMethodDecl(CXXMethodDecl* f)
+{
+ auto copy = currentFunctionDecl;
+ currentFunctionDecl = f;
+ bool ret = RecursiveASTVisitor::TraverseCXXMethodDecl(f);
+ currentFunctionDecl = copy;
+ return ret;
+}
+bool UnusedMethods::TraverseCXXConversionDecl(CXXConversionDecl* f)
+{
+ auto copy = currentFunctionDecl;
+ currentFunctionDecl = f;
+ bool ret = RecursiveASTVisitor::TraverseCXXConversionDecl(f);
+ currentFunctionDecl = copy;
+ return ret;
+}
+bool UnusedMethods::TraverseCXXDeductionGuideDecl(CXXDeductionGuideDecl* f)
+{
+ auto copy = currentFunctionDecl;
+ currentFunctionDecl = f;
+ bool ret = RecursiveASTVisitor::TraverseCXXDeductionGuideDecl(f);
+ currentFunctionDecl = copy;
+ return ret;
+}
+
loplugin::Plugin::Registration< UnusedMethods > X("unusedmethods", false);
}