[clang-tools-extra] bb5e66e - [include-cleaner] Suppress all clang warnings (#109099)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 02:16:54 PDT 2024


Author: kadir çetinkaya
Date: 2024-09-19T11:16:49+02:00
New Revision: bb5e66e31b2a5dbb2930728ff94281fd805f2d14

URL: https://github.com/llvm/llvm-project/commit/bb5e66e31b2a5dbb2930728ff94281fd805f2d14
DIFF: https://github.com/llvm/llvm-project/commit/bb5e66e31b2a5dbb2930728ff94281fd805f2d14.diff

LOG: [include-cleaner] Suppress all clang warnings (#109099)

This patch disables all clang warnings when running include-cleaner, as
users aren't interested in other findings and in-development code might
have them temporarily. This ensures tool can keep working even in
presence of such issues.

Added: 
    clang-tools-extra/include-cleaner/test/tool-ignores-warnings.cpp

Modified: 
    clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/test/tool-ignores-warnings.cpp b/clang-tools-extra/include-cleaner/test/tool-ignores-warnings.cpp
new file mode 100644
index 00000000000000..e207a32c950d5d
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/test/tool-ignores-warnings.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-include-cleaner %s -- -Wunused 2>&1 | FileCheck --allow-empty %s
+static void foo() {}
+
+// Make sure that we don't get an unused warning
+// CHECK-NOT: unused function

diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index d8a44ab9b6e12e..afae4365587aea 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -139,7 +139,17 @@ class Action : public clang::ASTFrontendAction {
   }
 
   void ExecuteAction() override {
-    auto &P = getCompilerInstance().getPreprocessor();
+    const auto &CI = getCompilerInstance();
+
+    // Disable all warnings when running include-cleaner, as we are only
+    // interested in include-cleaner related findings. This makes the tool both
+    // more resilient around in-development code, and possibly faster as we
+    // skip some extra analysis.
+    auto &Diags = CI.getDiagnostics();
+    Diags.setEnableAllWarnings(false);
+    Diags.setSeverityForAll(clang::diag::Flavor::WarningOrError,
+                            clang::diag::Severity::Ignored);
+    auto &P = CI.getPreprocessor();
     P.addPPCallbacks(PP.record(P));
     PI.record(getCompilerInstance());
     ASTFrontendAction::ExecuteAction();


        


More information about the cfe-commits mailing list