diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-06-10 13:11:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-06-14 09:07:13 +0200 |
commit | d0f61d94d6bd3e377083eba2c2de84442963c017 (patch) | |
tree | 586b0bf45b78ca9cf53b6a031e682aa6397bee8d /compilerplugins/clang/unusedmethods.cxx | |
parent | 5dd9aeb8250890047732ef5dca9072a0ecc32f58 (diff) |
better solution for ignoreLocation for tree-wide plugins
Change-Id: I7336003e038781d4ef50380fa49f66b5ff19379f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135589
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/unusedmethods.cxx')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 41b1317d4047..5b10eae7e9df 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -84,6 +84,8 @@ public: virtual void run() override { + handler.enableTreeWideAnalysisMode(); + StringRef fn(handler.getMainFileName()); // ignore external code, makes this run faster if (fn.contains("UnpackedTarball")) @@ -133,8 +135,6 @@ private: MyFuncInfo niceName(const FunctionDecl* functionDecl); std::string toString(SourceLocation loc); void functionTouchedFromExpr( const FunctionDecl* calleeFunctionDecl, const Expr* expr ); - bool ignoreLocation(SourceLocation loc); - bool checkIgnoreLocation(SourceLocation loc); CXXRecordDecl const * currentCxxRecordDecl = nullptr; FunctionDecl const * currentFunctionDecl = nullptr; @@ -197,41 +197,6 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl) return aInfo; } -/** - * Our need to see everything conflicts with the PCH code in pluginhandler::ignoreLocation, - * so we have to do this ourselves. - */ -bool UnusedMethods::ignoreLocation(SourceLocation loc) -{ - static std::unordered_map<SourceLocation, bool> checkedMap; - auto it = checkedMap.find(loc); - if (it != checkedMap.end()) - return it->second; - bool ignore = checkIgnoreLocation(loc); - checkedMap.emplace(loc, ignore); - return ignore; -} - -bool UnusedMethods::checkIgnoreLocation(SourceLocation loc) -{ - // simplified form of the code in PluginHandler::checkIgnoreLocation - SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( loc ); - if( compiler.getSourceManager().isInSystemHeader( expansionLoc )) - return true; - PresumedLoc presumedLoc = compiler.getSourceManager().getPresumedLoc( expansionLoc ); - if( presumedLoc.isInvalid()) - return true; - const char* bufferName = presumedLoc.getFilename(); - if (bufferName == NULL - || loplugin::hasPathnamePrefix(bufferName, SRCDIR "/external/") - || loplugin::hasPathnamePrefix(bufferName, WORKDIR "/")) - return true; - if( loplugin::hasPathnamePrefix(bufferName, BUILDDIR "/") - || loplugin::hasPathnamePrefix(bufferName, SRCDIR "/") ) - return false; // ok - return true; -} - std::string UnusedMethods::toString(SourceLocation loc) { SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( loc ); |