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

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 01:41:12 PDT 2024


https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/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.


>From 5eb5a0cebc789ca0b26f9212af5ae3695274ca38 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <kadircet at google.com>
Date: Wed, 18 Sep 2024 10:38:55 +0200
Subject: [PATCH] [include-cleaner] Suppress all clang warnings

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.
---
 .../include-cleaner/test/tool-ignores-warnings.cpp   |  5 +++++
 .../include-cleaner/tool/IncludeCleaner.cpp          | 12 +++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang-tools-extra/include-cleaner/test/tool-ignores-warnings.cpp

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