From 2c8fe2e737b84ecd3dbac36a4fe6bd061bbd3bae Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 16 May 2016 10:11:04 +0200 Subject: update unusedmethods plugin to deal with constructors and fix the operator< implementations in some of the other plugins too. Change-Id: Ie5631e0cdc8d2a994ad2af2533cdb558a6cfc035 Reviewed-on: https://gerrit.libreoffice.org/25057 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/constantparam.cxx | 11 ++------- compilerplugins/clang/unuseddefaultparams.cxx | 3 ++- compilerplugins/clang/unusedfields.cxx | 8 ++----- compilerplugins/clang/unusedmethods.cxx | 33 ++++++++++++++++++++------- 4 files changed, 31 insertions(+), 24 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index 570cb96ca9f5..99db54554dbd 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -38,15 +38,8 @@ struct MyCallSiteInfo }; bool operator < (const MyCallSiteInfo &lhs, const MyCallSiteInfo &rhs) { - if (lhs.sourceLocation < rhs.sourceLocation) - return true; - else if (lhs.sourceLocation > rhs.sourceLocation) - return false; - else if (lhs.paramIndex < rhs.paramIndex) - return true; - else if (lhs.paramIndex > rhs.paramIndex) - return false; - else return lhs.callValue < rhs.callValue; + return std::tie(lhs.sourceLocation, lhs.paramIndex, lhs.callValue) + < std::tie(rhs.sourceLocation, rhs.paramIndex, rhs.callValue); } diff --git a/compilerplugins/clang/unuseddefaultparams.cxx b/compilerplugins/clang/unuseddefaultparams.cxx index 21979eaa780c..0a3ce28cc761 100644 --- a/compilerplugins/clang/unuseddefaultparams.cxx +++ b/compilerplugins/clang/unuseddefaultparams.cxx @@ -36,7 +36,8 @@ struct MyFuncInfo }; bool operator < (const MyFuncInfo &lhs, const MyFuncInfo &rhs) { - return lhs.sourceLocation < rhs.sourceLocation; + return std::tie(lhs.returnType, lhs.nameAndParams) + < std::tie(rhs.returnType, rhs.nameAndParams); } diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index dd928d302772..a370cb37c449 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -50,12 +50,8 @@ struct MyFieldInfo }; bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs) { - if (lhs.parentClass < rhs.parentClass) - return true; - else if (lhs.parentClass == rhs.parentClass) - return lhs.fieldName < rhs.fieldName; - else - return false; + return std::tie(lhs.parentClass, lhs.fieldName) + < std::tie(rhs.parentClass, rhs.fieldName); } diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index e0b971882a51..fe5825fbfd4f 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -25,12 +25,12 @@ This plugin performs 3 different analyses: It does so, by dumping various call/definition/use info to a log file. Then we will post-process the various lists and find the set of unused methods. -Be warned that it produces around 5G of log file. +Be warned that it produces around 15G of log file. The process goes something like this: $ make check $ make FORCE_COMPILE_ALL=1 COMPILER_PLUGIN_TOOL='unusedmethods' check - $ ./compilerplugins/clang/unusedmethods.py unusedmethods.log > result.txt + $ ./compilerplugins/clang/unusedmethods.py unusedmethods.log and then $ for dir in *; do make FORCE_COMPILE_ALL=1 UPDATE_FILES=$dir COMPILER_PLUGIN_TOOL='unusedmethodsremove' $dir; done @@ -55,7 +55,8 @@ struct MyFuncInfo }; bool operator < (const MyFuncInfo &lhs, const MyFuncInfo &rhs) { - return lhs.sourceLocation < rhs.sourceLocation; + return std::tie(lhs.returnType, lhs.nameAndParams) + < std::tie(rhs.returnType, rhs.nameAndParams); } // try to limit the voluminous output a little @@ -102,10 +103,12 @@ public: } bool shouldVisitTemplateInstantiations () const { return true; } + bool shouldVisitImplicitCode() const { return true; } bool VisitCallExpr(CallExpr* ); bool VisitFunctionDecl( const FunctionDecl* decl ); bool VisitDeclRefExpr( const DeclRefExpr* ); + bool VisitCXXConstructExpr( const CXXConstructExpr* ); private: void logCallToRootMethods(const FunctionDecl* functionDecl, std::set& funcSet); MyFuncInfo niceName(const FunctionDecl* functionDecl); @@ -132,7 +135,11 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl) case AS_protected: aInfo.access = "protected"; break; default: aInfo.access = "unknown"; break; } - aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); + if (!isa(functionDecl)) { + aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); + } else { + aInfo.returnType = ""; + } if (isa(functionDecl)) { const CXXRecordDecl* recordDecl = dyn_cast(functionDecl)->getParent(); @@ -308,6 +315,19 @@ gotfunc: return true; } +bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) +{ + // Note that I don't ignore ANYTHING here, because I want to get calls to my code that result + // from template instantiation deep inside the STL and other external code + + const CXXConstructorDecl* constructorDecl = constructExpr->getConstructor(); + constructorDecl = constructorDecl->getCanonicalDecl(); + + logCallToRootMethods(constructorDecl, callSet); + + return true; +} + bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl ) { functionDecl = functionDecl->getCanonicalDecl(); @@ -325,10 +345,7 @@ bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl ) if (isa(functionDecl)) { return true; } - if (isa(functionDecl)) { - return true; - } - if (functionDecl && functionDecl->isDeleted()) { + if (functionDecl->isDeleted() || functionDecl->isDefaulted()) { return true; } -- cgit