[clang-tools-extra] d3cfc71 - [include-cleaner] Always keep non-self-contained files (#65499)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 10 22:22:56 PDT 2023
Author: kadir çetinkaya
Date: 2023-09-11T07:22:52+02:00
New Revision: d3cfc7126c160641bc2630cdf2cbdb61abf8bc6d
URL: https://github.com/llvm/llvm-project/commit/d3cfc7126c160641bc2630cdf2cbdb61abf8bc6d
DIFF: https://github.com/llvm/llvm-project/commit/d3cfc7126c160641bc2630cdf2cbdb61abf8bc6d.diff
LOG: [include-cleaner] Always keep non-self-contained files (#65499)
Added:
Modified:
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index b90bab70c4d90a8..5a6524dec2f09a6 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -88,10 +88,10 @@ TEST(IncludeCleaner, StdlibUnused) {
template <typename> class vector {};
}
)cpp";
- TU.AdditionalFiles["list"] = "#include <bits>";
- TU.AdditionalFiles["queue"] = "#include <bits>";
- TU.AdditionalFiles["vector"] = "#include <bits>";
- TU.AdditionalFiles["string"] = "#include <bits>";
+ TU.AdditionalFiles["list"] = guard("#include <bits>");
+ TU.AdditionalFiles["queue"] = guard("#include <bits>");
+ TU.AdditionalFiles["vector"] = guard("#include <bits>");
+ TU.AdditionalFiles["string"] = guard("#include <bits>");
TU.ExtraArgs = {"-isystem", testRoot()};
auto AST = TU.build();
IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp
index f3253fec01bf9a5..4e96e8eb208b7da 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -430,7 +430,8 @@ bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
}
bool PragmaIncludes::shouldKeep(const FileEntry *FE) const {
- return ShouldKeep.contains(FE->getUniqueID());
+ return ShouldKeep.contains(FE->getUniqueID()) ||
+ NonSelfContainedFiles.contains(FE->getUniqueID());
}
namespace {
diff --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index 4f3b5c7ace65ebd..36850731d514539 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -320,7 +320,7 @@ class PragmaIncludeTest : public ::testing::Test {
void createEmptyFiles(llvm::ArrayRef<StringRef> FileNames) {
for (llvm::StringRef File : FileNames)
- Inputs.ExtraFiles[File] = "";
+ Inputs.ExtraFiles[File] = "#pragma once";
}
};
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index f84133b01a3a49f..0c29b469b617b7c 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -47,9 +47,10 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
const char *PostCode = "\n";
std::vector<ClangTidyError> Errors;
- EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
- PreCode, &Errors, "file.cpp", std::nullopt,
- ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+ EXPECT_EQ(PostCode,
+ runCheckOnCode<IncludeCleanerCheck>(
+ PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+ {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}}));
}
TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
@@ -76,10 +77,11 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
PostCode,
runCheckOnCode<IncludeCleanerCheck>(
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
- {{"bar.h", ""},
- {"vector", ""},
- {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
- {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+ {{"bar.h", "#pragma once"},
+ {"vector", "#pragma once"},
+ {appendPathFileSystemIndependent({"foo", "qux.h"}), "#pragma once"},
+ {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}),
+ "#pragma once"}}));
}
TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
More information about the cfe-commits
mailing list