https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/124141

>From 56faefda954130f1f67d160d6ccc98e50f22674c Mon Sep 17 00:00:00 2001
From: James Y Knight <jykni...@google.com>
Date: Thu, 23 Jan 2025 11:02:20 -0500
Subject: [PATCH 1/2] [Clang] Silently ignore unknown warnings in
 `--warning-suppression-mappings`.

This allows the same file to be used on multiple Clang versions,
without generating output spam.

Also disable parsing of the suppressions file in the Driver, where
it's not needed. This was previously causing the diagnostics to be
emitted twice, as the file was being parsed twice.

I'll also note that if we do ever wish to emit non-fatal diagnostics
from parsing this file, it'll need more: the code deleted here emitted
warnings which were not possible for a user to disable, since the
suppression file is parsed _before_ the diagnostic state has been
setup.
---
 clang/lib/Basic/Diagnostic.cpp                 | 8 +++-----
 clang/test/Misc/Inputs/suppression-mapping.txt | 4 ++++
 clang/tools/driver/driver.cpp                  | 3 +++
 clang/unittests/Basic/DiagnosticTest.cpp       | 3 +--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index ae71758bc81e03..55efd5ffafcece 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -547,11 +547,9 @@ void 
WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
     StringRef DiagGroup = SectionEntry->getKey();
     if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
             WarningFlavor, DiagGroup, GroupDiags)) {
-      StringRef Suggestion =
-          DiagnosticIDs::getNearestOption(WarningFlavor, DiagGroup);
-      Diags.Report(diag::warn_unknown_diag_option)
-          << static_cast<unsigned>(WarningFlavor) << DiagGroup
-          << !Suggestion.empty() << Suggestion;
+      // If a diagnostic group name is unknown, simply ignore the
+      // suppressions. This allows use of a single suppression file on multiple
+      // versions of clang.
       continue;
     }
     for (diag::kind Diag : GroupDiags)
diff --git a/clang/test/Misc/Inputs/suppression-mapping.txt 
b/clang/test/Misc/Inputs/suppression-mapping.txt
index abe4fde0c265d5..cea8c50daee1c5 100644
--- a/clang/test/Misc/Inputs/suppression-mapping.txt
+++ b/clang/test/Misc/Inputs/suppression-mapping.txt
@@ -11,3 +11,7 @@ src:*foo/*=emit
 [format=2]
 src:*
 src:*foo/*=emit
+
+# A warning group that clang doesn't know about should be silently ignored.
+[barglegunk]
+src:*
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 74923247b7ee16..c68367c177910c 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -319,6 +319,9 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
       CreateAndPopulateDiagOpts(Args);
 
+  // The _driver_ (vs cc1) diagnostics engine shouldn't bother to load a 
suppression file.
+  DiagOpts->DiagnosticSuppressionMappingsFile = "";
+
   TextDiagnosticPrinter *DiagClient
     = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
   FixupDiagPrefixExeName(DiagClient, ProgName);
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index e03d9a464df7f9..6c431ed81c4919 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -253,8 +253,7 @@ TEST_F(SuppressionMappingTest, UnknownDiagName) {
   FS->addFile("foo.txt", /*ModificationTime=*/{},
               llvm::MemoryBuffer::getMemBuffer("[non-existing-warning]"));
   clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
-  EXPECT_THAT(diags(), ElementsAre(WithMessage(
-                           "unknown warning option 'non-existing-warning'")));
+  EXPECT_THAT(diags(), IsEmpty());
 }
 
 TEST_F(SuppressionMappingTest, SuppressesGroup) {

>From c67cf0bb57fb850aab42d5a382fdc15aaff2967d Mon Sep 17 00:00:00 2001
From: James Y Knight <jykni...@google.com>
Date: Thu, 23 Jan 2025 11:16:41 -0500
Subject: [PATCH 2/2] clang-format.

---
 clang/tools/driver/driver.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c68367c177910c..5ef64a6a6ad991 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -319,7 +319,8 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
       CreateAndPopulateDiagOpts(Args);
 
-  // The _driver_ (vs cc1) diagnostics engine shouldn't bother to load a 
suppression file.
+  // The _driver_ (vs cc1) diagnostics engine shouldn't bother to load a
+  // suppression file.
   DiagOpts->DiagnosticSuppressionMappingsFile = "";
 
   TextDiagnosticPrinter *DiagClient

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to