From 87ce5c48e9730eb0700d5a5a0f4cf9e9fc2d9fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kadir=20=C3=A7etinkaya?= Date: Thu, 19 Sep 2024 11:16:49 +0200 Subject: [PATCH] [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. --- .../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();