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/unusedfields.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/unusedfields.cxx')
-rw-r--r-- | compilerplugins/clang/unusedfields.cxx | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index 24045483ffe1..dac13318649c 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -163,8 +163,6 @@ public: private: MyFieldInfo niceName(const FieldDecl*); - bool ignoreLocation(SourceLocation loc); - bool checkIgnoreLocation(SourceLocation loc); void checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr); void checkIfReadFrom(const FieldDecl* fieldDecl, const Expr* memberExpr); void checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memberExpr); @@ -184,6 +182,8 @@ private: void UnusedFields::run() { + handler.enableTreeWideAnalysisMode(); + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); if (!isUnitTestMode()) @@ -281,42 +281,6 @@ MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl) return aInfo; } -/** - * Our need to see everything conflicts with the PCH code in pluginhandler::ignoreLocation, - * so we have to do this ourselves. - */ -bool UnusedFields::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 UnusedFields::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; -} - - bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl ) { fieldDecl = fieldDecl->getCanonicalDecl(); |