diff options
author | Viktoriia Bakalova <bakalova@google.com> | 2023-08-10 13:11:13 +0000 |
---|---|---|
committer | Viktoriia Bakalova <bakalova@google.com> | 2023-09-07 11:39:18 +0000 |
commit | 43c20367f417410a736959d4ae53f374e0d5b500 (patch) | |
tree | afc2c199b19ddeecef2eda87f5f91889a78ddfe3 /clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | |
parent | 99789344d38b4918d830169a5ba343c1301e8782 (diff) | |
download | llvm-43c20367f417410a736959d4ae53f374e0d5b500.zip llvm-43c20367f417410a736959d4ae53f374e0d5b500.tar.gz llvm-43c20367f417410a736959d4ae53f374e0d5b500.tar.bz2 |
[include-cleaner][clangd][clang-tidy] Ignore resource dir during include-cleaner analysis.
Differential Revision: https://reviews.llvm.org/D157610
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp index 8d5f400..8e460cb 100644 --- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp @@ -26,6 +26,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Format/Format.h" +#include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/Preprocessor.h" #include "clang/Tooling/Core/Replacement.h" #include "clang/Tooling/Inclusions/HeaderIncludes.h" @@ -119,6 +120,8 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { MainFileDecls.push_back(D); } llvm::DenseSet<include_cleaner::Symbol> SeenSymbols; + const DirectoryEntry *ResourceDir = + PP->getHeaderSearchInfo().getModuleMap().getBuiltinDir(); // FIXME: Find a way to have less code duplication between include-cleaner // analysis implementation and the below code. walkUsed(MainFileDecls, RecordedPreprocessor.MacroReferences, &RecordedPI, @@ -141,8 +144,11 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { bool Satisfied = false; for (const include_cleaner::Header &H : Providers) { if (H.kind() == include_cleaner::Header::Physical && - H.physical() == MainFile) + (H.physical() == MainFile || + H.physical()->getDir() == ResourceDir)) { Satisfied = true; + continue; + } for (const include_cleaner::Include *I : RecordedPreprocessor.Includes.match(H)) { @@ -159,7 +165,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { std::vector<const include_cleaner::Include *> Unused; for (const include_cleaner::Include &I : RecordedPreprocessor.Includes.all()) { - if (Used.contains(&I) || !I.Resolved) + if (Used.contains(&I) || !I.Resolved || I.Resolved->getDir() == ResourceDir) continue; if (RecordedPI.shouldKeep(*I.Resolved)) continue; |