summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-05-16 10:11:04 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-05-18 10:03:44 +0000
commit2c8fe2e737b84ecd3dbac36a4fe6bd061bbd3bae (patch)
tree66ba7ff0b95cf5ceeda5e53294a71c6786460eb3 /compilerplugins
parentadd D.M.Y date pattern to Gaelic [gd-GB] (diff)
downloadcore-2c8fe2e737b84ecd3dbac36a4fe6bd061bbd3bae.tar.gz
core-2c8fe2e737b84ecd3dbac36a4fe6bd061bbd3bae.zip
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 <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/constantparam.cxx11
-rw-r--r--compilerplugins/clang/unuseddefaultparams.cxx3
-rw-r--r--compilerplugins/clang/unusedfields.cxx8
-rw-r--r--compilerplugins/clang/unusedmethods.cxx33
4 files changed, 31 insertions, 24 deletions
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<MyFuncInfo>& 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<CXXConstructorDecl>(functionDecl)) {
+ aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString();
+ } else {
+ aInfo.returnType = "";
+ }
if (isa<CXXMethodDecl>(functionDecl)) {
const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(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<CXXDestructorDecl>(functionDecl)) {
return true;
}
- if (isa<CXXConstructorDecl>(functionDecl)) {
- return true;
- }
- if (functionDecl && functionDecl->isDeleted()) {
+ if (functionDecl->isDeleted() || functionDecl->isDefaulted()) {
return true;
}