[clang-tools-extra] [clang-tidy] Fix crash in misc-include-cleaner on invalid config (PR #243739)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 17 22:17:36 PST 2026
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/243739
>From eca55f9a7ac494b3ea9c3fc231bc042a50cbea55 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 18 Nov 2026 05:41:54 +0000
Subject: [PATCH 1/2] [clang-tidy] Fix crash in misc-include-cleaner on invalid
config
---
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 4 ++--
clang-tools-extra/docs/ReleaseNotes.md | 4 ++++
.../checkers/misc/include-cleaner-invalid-format.cpp | 6 ++++++
3 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index fc13b8aef2d8b2..329a369658cf82 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -203,10 +203,10 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
}
const StringRef Code = SM->getBufferData(SM->getMainFileID());
- auto FileStyle =
+ auto FileStyle = llvm::expectedToOptional(
format::getStyle(format::DefaultFormatStyle, getCurrentMainFile(),
format::DefaultFallbackStyle, Code,
- &SM->getFileManager().getVirtualFileSystem());
+ &SM->getFileManager().getVirtualFileSystem()));
if (!FileStyle)
FileStyle = format::getLLVMStyle();
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 2566c24544d706..f203591b6fe626 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -302,6 +302,10 @@ infrastructure are described first, followed by tool-specific sections.
{option}`IgnoreHeaders` patterns containing `/` against header paths on
Windows.
+- Improved {doc}`misc-include-cleaner
+ <clang-tidy/checks/misc/include-cleaner>` check by fixing a crash when a
+ `.clang-format` file contains invalid configuration, such as duplicate keys.
+
- 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/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp
new file mode 100644
index 00000000000000..ef19dce29f809a
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp
@@ -0,0 +1,6 @@
+// RUN: mkdir -p %t.dir
+// RUN: echo 'IndentWidth: 2' > %t.dir/.clang-format
+// RUN: echo 'IndentWidth: 4' >> %t.dir/.clang-format
+// RUN: %check_clang_tidy %s misc-include-cleaner %t.dir/repro
+
+// CHECK-MESSAGES: error: duplicated mapping key 'IndentWidth'
>From 1bf7a0d7f92881c041f54235b94a4baad3c9f683 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 18 Nov 2026 06:16:57 +0000
Subject: [PATCH 2/2] ~
---
clang-tools-extra/docs/ReleaseNotes.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index f203591b6fe626..98a385feaa5898 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -298,13 +298,13 @@ infrastructure are described first, followed by tool-specific sections.
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.
+ <clang-tidy/checks/misc/include-cleaner>` check:
-- Improved {doc}`misc-include-cleaner
- <clang-tidy/checks/misc/include-cleaner>` check by fixing a crash when a
- `.clang-format` file contains invalid configuration, such as duplicate keys.
+ - Match {option}`IgnoreHeaders` patterns containing `/` against header paths
+ on Windows.
+
+ - Fix a crash when a `.clang-format` file contains invalid configuration, such
+ as duplicate keys.
- Fixed an infinite loop in {doc}`misc-multiple-inheritance
<clang-tidy/checks/misc/multiple-inheritance>` when checking a class that
More information about the cfe-commits
mailing list