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();