Skip to content

Conversation

@vbvictor
Copy link
Contributor

Enabling misc-include-cleaner with a couple of IWYU pragma: keep lines seems beneficial to me:

In my observation, we've made far more comments in reviews like "this header seems unused" than we've looked at includes of "top-level" files like ClangTidy.cpp, ClangTidyForceLinker.h, ClangTidyMain.cpp and so on.
So I think it's a net benefit to keep check files clean from unused headers (which we review a lot) but make rarely-touched areas a little "polluted" with IWYU pragma's

- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false
- key: misc-include-cleaner.MissingIncludes
value: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set MissingIncludes because the LLVM coding standard doesn't follow "IWYU" but rather follow "use forward declaration, include as little as possible" https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Clang Include Cleaner is noisy for class hierarchies located in different headers. It also doesn't work with headers unless compile database copied and tweaked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real IWYU does support this policy, but I guess it's not trivial to integrate here...

@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2025

@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)

Changes

Enabling misc-include-cleaner with a couple of IWYU pragma: keep lines seems beneficial to me:

In my observation, we've made far more comments in reviews like "this header seems unused" than we've looked at includes of "top-level" files like ClangTidy.cpp, ClangTidyForceLinker.h, ClangTidyMain.cpp and so on.
So I think it's a net benefit to keep check files clean from unused headers (which we review a lot) but make rarely-touched areas a little "polluted" with IWYU pragma's


Full diff: https://github.com/llvm/llvm-project/pull/171903.diff

7 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (+3)
  • (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/ClangTidyForceLinker.h (+1-1)
  • (modified) clang-tools-extra/clang-tidy/GlobList.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp (-1)
  • (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp (+2-4)
  • (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+2-2)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 70d57315260c0..94df1d8f5c38f 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -15,6 +15,7 @@ Checks: >
   cppcoreguidelines-virtual-class-destructor,
   google-readability-casting,
   misc-const-correctness,
+  misc-include-cleaner,
   modernize-*,
   -modernize-avoid-c-arrays,
   -modernize-pass-by-value,
@@ -42,3 +43,5 @@ Checks: >
 CheckOptions:
   - key:             performance-move-const-arg.CheckTriviallyCopyableMove
     value:           false
+  - key:             misc-include-cleaner.MissingIncludes
+    value:           false
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 4af328cd5110a..37806a42acafd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -33,7 +33,7 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Rewrite/Frontend/FixItRewriter.h"
 #include "clang/Tooling/Core/Diagnostic.h"
-#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/DiagnosticsYaml.h" // IWYU pragma: keep
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Process.h"
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index afc358ad4e966..03489acb7598e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H
 
 #include "clang-tidy-config.h"
-#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compiler.h" // IWYU pragma: keep
 
 namespace clang::tidy {
 
diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp
index 5d5a5f2d8d865..e908434852295 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -31,7 +31,7 @@ static llvm::StringRef extractNextGlob(StringRef &GlobList) {
 }
 
 static llvm::Regex createRegexFromGlob(StringRef &Glob) {
-  SmallString<128> RegexText("^");
+  llvm::SmallString<128> RegexText("^");
   const StringRef MetaChars("()^$|*+?.[]\\{}");
   for (const char C : Glob) {
     if (C == '*')
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 0315728f851d1..02414668c673c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -27,7 +27,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/MathExtras.h"
 #include <array>
 #include <cmath>
 #include <cstdint>
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 79f8437057b23..1477c52cd7d3a 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -16,7 +16,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/YAMLParser.h"
@@ -1363,9 +1362,8 @@ IdentifierNamingCheck::getFailureInfo(
   if (StringRef(Fixup) == Name) {
     if (!IgnoreFailedSplit) {
       LLVM_DEBUG(Location.print(llvm::dbgs(), SM);
-                 llvm::dbgs()
-                 << llvm::formatv(": unable to split words for {0} '{1}'\n",
-                                  KindName, Name));
+                 llvm::dbgs() << ": unable to split words for " << KindName
+                              << " '" << Name << "'\n");
     }
     return std::nullopt;
   }
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 6a1f61dd6b9e1..12d425d42fc20 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -16,13 +16,13 @@
 
 #include "ClangTidyMain.h"
 #include "../ClangTidy.h"
-#include "../ClangTidyForceLinker.h"
+#include "../ClangTidyForceLinker.h" // IWYU pragma: keep
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/PluginLoader.h" // IWYU pragma: keep
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"

@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Baranov Victor (vbvictor)

Changes

Enabling misc-include-cleaner with a couple of IWYU pragma: keep lines seems beneficial to me:

In my observation, we've made far more comments in reviews like "this header seems unused" than we've looked at includes of "top-level" files like ClangTidy.cpp, ClangTidyForceLinker.h, ClangTidyMain.cpp and so on.
So I think it's a net benefit to keep check files clean from unused headers (which we review a lot) but make rarely-touched areas a little "polluted" with IWYU pragma's


Full diff: https://github.com/llvm/llvm-project/pull/171903.diff

7 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (+3)
  • (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/ClangTidyForceLinker.h (+1-1)
  • (modified) clang-tools-extra/clang-tidy/GlobList.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp (-1)
  • (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp (+2-4)
  • (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+2-2)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 70d57315260c0..94df1d8f5c38f 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -15,6 +15,7 @@ Checks: >
   cppcoreguidelines-virtual-class-destructor,
   google-readability-casting,
   misc-const-correctness,
+  misc-include-cleaner,
   modernize-*,
   -modernize-avoid-c-arrays,
   -modernize-pass-by-value,
@@ -42,3 +43,5 @@ Checks: >
 CheckOptions:
   - key:             performance-move-const-arg.CheckTriviallyCopyableMove
     value:           false
+  - key:             misc-include-cleaner.MissingIncludes
+    value:           false
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 4af328cd5110a..37806a42acafd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -33,7 +33,7 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Rewrite/Frontend/FixItRewriter.h"
 #include "clang/Tooling/Core/Diagnostic.h"
-#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/DiagnosticsYaml.h" // IWYU pragma: keep
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Process.h"
diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index afc358ad4e966..03489acb7598e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H
 
 #include "clang-tidy-config.h"
-#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compiler.h" // IWYU pragma: keep
 
 namespace clang::tidy {
 
diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp
index 5d5a5f2d8d865..e908434852295 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -31,7 +31,7 @@ static llvm::StringRef extractNextGlob(StringRef &GlobList) {
 }
 
 static llvm::Regex createRegexFromGlob(StringRef &Glob) {
-  SmallString<128> RegexText("^");
+  llvm::SmallString<128> RegexText("^");
   const StringRef MetaChars("()^$|*+?.[]\\{}");
   for (const char C : Glob) {
     if (C == '*')
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 0315728f851d1..02414668c673c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -27,7 +27,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/MathExtras.h"
 #include <array>
 #include <cmath>
 #include <cstdint>
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 79f8437057b23..1477c52cd7d3a 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -16,7 +16,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/YAMLParser.h"
@@ -1363,9 +1362,8 @@ IdentifierNamingCheck::getFailureInfo(
   if (StringRef(Fixup) == Name) {
     if (!IgnoreFailedSplit) {
       LLVM_DEBUG(Location.print(llvm::dbgs(), SM);
-                 llvm::dbgs()
-                 << llvm::formatv(": unable to split words for {0} '{1}'\n",
-                                  KindName, Name));
+                 llvm::dbgs() << ": unable to split words for " << KindName
+                              << " '" << Name << "'\n");
     }
     return std::nullopt;
   }
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 6a1f61dd6b9e1..12d425d42fc20 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -16,13 +16,13 @@
 
 #include "ClangTidyMain.h"
 #include "../ClangTidy.h"
-#include "../ClangTidyForceLinker.h"
+#include "../ClangTidyForceLinker.h" // IWYU pragma: keep
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/PluginLoader.h" // IWYU pragma: keep
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"

Copy link
Contributor

@localspook localspook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable tradeoff. (I'm only considering it in the abstract though, I don't think I've seen enough PRs to judge how common "this header seems unused" comments are).

Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>
@vbvictor vbvictor merged commit 5fcf712 into llvm:main Dec 15, 2025
11 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Dec 19, 2025
…vm#171903)

Enabling `misc-include-cleaner` with a couple of `IWYU pragma: keep`
lines seems beneficial to me:

In my observation, we've made far more comments in reviews like "this
header seems unused" than we've looked at includes of "top-level" files
like `ClangTidy.cpp`, `ClangTidyForceLinker.h`, `ClangTidyMain.cpp` and
so on.
So I think it's a net benefit to keep check files clean from unused
headers (which we review a lot) but make rarely-touched areas a little
"polluted" with `IWYU pragma`'s

---------

Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants