summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedmethods.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/unusedmethods.cxx')
-rw-r--r--compilerplugins/clang/unusedmethods.cxx30
1 files changed, 19 insertions, 11 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index 610f4a1974d5..5b10eae7e9df 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -17,6 +17,8 @@
#include "clang/AST/Attr.h"
+#include "config_clang.h"
+
#include "plugin.hxx"
/**
@@ -33,11 +35,11 @@ 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
+ $ make FORCE_COMPILE=all COMPILER_PLUGIN_TOOL='unusedmethods' check
$ ./compilerplugins/clang/unusedmethods.py
and then
- $ for dir in *; do make FORCE_COMPILE_ALL=1 UPDATE_FILES=$dir COMPILER_PLUGIN_TOOL='unusedmethodsremove' $dir; done
+ $ for dir in *; do make FORCE_COMPILE=all UPDATE_FILES=$dir COMPILER_PLUGIN_TOOL='unusedmethodsremove' $dir; done
to auto-remove the method declarations
Note that the actual process may involve a fair amount of undoing, hand editing, and general messing around
@@ -82,6 +84,13 @@ public:
virtual void run() override
{
+ handler.enableTreeWideAnalysisMode();
+
+ StringRef fn(handler.getMainFileName());
+ // ignore external code, makes this run faster
+ if (fn.contains("UnpackedTarball"))
+ return;
+
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
// dump all our output in one write call - this is to try and limit IO "crosstalk" between multiple processes
@@ -89,8 +98,10 @@ public:
std::string output;
for (const MyFuncInfo & s : definitionSet)
+ {
output += "definition:\t" + s.access + "\t" + s.returnType + "\t" + s.nameAndParams
+ "\t" + s.sourceLocation + "\t" + s.virtualness + "\n";
+ }
// for the "unused method" analysis
for (const MyFuncInfo & s : callSet)
output += "call:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
@@ -124,6 +135,7 @@ private:
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;
};
@@ -134,10 +146,6 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
{
if (functionDecl->getInstantiatedFromMemberFunction())
functionDecl = functionDecl->getInstantiatedFromMemberFunction();
-#if CLANG_VERSION < 90000
- else if (functionDecl->getClassScopeSpecializationPattern())
- functionDecl = functionDecl->getClassScopeSpecializationPattern();
-#endif
else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();
else
@@ -217,7 +225,7 @@ void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl, std::
{
while (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();
- if (functionDecl->getLocation().isValid() && !ignoreLocation( functionDecl )
+ if (functionDecl->getLocation().isValid() && !ignoreLocation( functionDecl->getBeginLoc() )
&& !functionDecl->isExternC())
funcSet.insert(niceName(functionDecl));
}
@@ -262,7 +270,7 @@ gotfunc:
{
const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(expr);
if (parentFunctionOfCallSite != calleeFunctionDecl) {
- if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) {
+ if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite->getBeginLoc())) {
calledFromOutsideSet.insert(niceName(calleeFunctionDecl));
}
}
@@ -302,7 +310,7 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
const CXXConstructorDecl* constructorDecl = constructExpr->getConstructor();
constructorDecl = constructorDecl->getCanonicalDecl();
- if (!constructorDecl->getLocation().isValid() || ignoreLocation(constructorDecl)) {
+ if (!constructorDecl->getLocation().isValid() || ignoreLocation(constructorDecl->getBeginLoc())) {
return true;
}
@@ -333,7 +341,7 @@ bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl )
{
return true;
}
- if (!canonicalFunctionDecl->getLocation().isValid() || ignoreLocation(canonicalFunctionDecl)) {
+ if (!canonicalFunctionDecl->getLocation().isValid() || ignoreLocation(canonicalFunctionDecl->getBeginLoc())) {
return true;
}
// ignore method overrides, since the call will show up as being directed to the root method
@@ -363,7 +371,7 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
{
const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(declRefExpr);
if (parentFunctionOfCallSite != functionDecl) {
- if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) {
+ if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite->getBeginLoc())) {
calledFromOutsideSet.insert(niceName(functionDecl));
}
}