[clang-tools-extra] [clang-tidy] Match IgnoreHeaders against slash-normalized paths in misc-include-cleaner (PR #237924)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 04:02:01 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Zeyi Xu (zeyi2)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/237924.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp (+4-2)
- (modified) clang-tools-extra/docs/ReleaseNotes.md (+5)
- (modified) clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp (+15)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 0097ea54ba5482..fc13b8aef2d8b2 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -111,8 +111,10 @@ bool IncludeCleanerCheck::shouldIgnore(const include_cleaner::Header &H) {
return R.match(H.standard().name());
case include_cleaner::Header::Verbatim:
return R.match(H.verbatim().trim("<>\""));
- case include_cleaner::Header::Physical:
- return R.match(H.physical().getFileEntry().tryGetRealPathName());
+ case include_cleaner::Header::Physical: {
+ const StringRef Path = H.physical().getFileEntry().tryGetRealPathName();
+ return R.match(Path) || R.match(llvm::sys::path::convert_to_slash(Path));
+ }
}
llvm_unreachable("Unknown Header kind.");
});
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 679ca9ecbb4a39..63e036e123cb8c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -274,6 +274,11 @@ infrastructure are described first, followed by tool-specific sections.
instantiations, where the suggested `const` would break the move for
instantiations with real move semantics.
+- Improved {doc}`misc-include-cleaner
+ <clang-tidy/checks/misc/include-cleaner>` check by matching
+ {option}`IgnoreHeaders` patterns containing `/` against header paths on
+ Windows.
+
- Fixed an infinite loop in {doc}`misc-multiple-inheritance
<clang-tidy/checks/misc/multiple-inheritance>` when checking a class that
inherits from itself or has a circular inheritance graph.
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index 00576916492e16..ff75f9008e489f 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -89,6 +89,21 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
"#pragma once"}}));
}
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludesForwardSlashPattern) {
+ const char *Code = R"(
+#include "foo/qux.h"
+)";
+
+ std::vector<ClangTidyError> Errors;
+ ClangTidyOptions Opts;
+ Opts.CheckOptions["test-check-0.IgnoreHeaders"] = ".*/qux\\.h";
+ EXPECT_EQ(Code, runCheckOnCode<IncludeCleanerCheck>(
+ Code, &Errors, "file.cpp", {}, Opts,
+ {{appendPathFileSystemIndependent({"foo", "qux.h"}),
+ "#pragma once"}}));
+ EXPECT_THAT(Errors.size(), testing::Eq(0U));
+}
+
TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
const char *PreCode = R"(
#include "bar.h"
``````````
</details>
https://github.com/llvm/llvm-project/pull/237924
More information about the cfe-commits
mailing list