Skip to content

[clang] Parse warning-suppression-mapping after setting up diagengine #125714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

kadircet
Copy link
Member

@kadircet kadircet commented Feb 4, 2025

We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 4, 2025
@kadircet kadircet requested a review from jyknight February 4, 2025 16:33
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2025

@llvm/pr-subscribers-clang

Author: kadir çetinkaya (kadircet)

Changes

We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.


Full diff: https://github.com/llvm/llvm-project/pull/125714.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Warnings.cpp (+13-10)
  • (modified) clang/unittests/Basic/DiagnosticTest.cpp (+9)
diff --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp
index da0304463007b65..5f48e0ec8155434 100644
--- a/clang/lib/Basic/Warnings.cpp
+++ b/clang/lib/Basic/Warnings.cpp
@@ -73,16 +73,6 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
   else
     Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
 
-  if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
-    if (auto FileContents =
-            VFS.getBufferForFile(Opts.DiagnosticSuppressionMappingsFile)) {
-      Diags.setDiagSuppressionMapping(**FileContents);
-    } else if (ReportDiags) {
-      Diags.Report(diag::err_drv_no_such_file)
-          << Opts.DiagnosticSuppressionMappingsFile;
-    }
-  }
-
   SmallVector<diag::kind, 10> _Diags;
   const IntrusiveRefCntPtr< DiagnosticIDs > DiagIDs =
     Diags.getDiagnosticIDs();
@@ -237,4 +227,17 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
       }
     }
   }
+
+  // Process suppression mappings file after processing other warning flags
+  // (like -Wno-unknown-warning-option) as we can emit extra warnings during
+  // processing.
+  if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
+    if (auto FileContents =
+            VFS.getBufferForFile(Opts.DiagnosticSuppressionMappingsFile)) {
+      Diags.setDiagSuppressionMapping(**FileContents);
+    } else if (ReportDiags) {
+      Diags.Report(diag::err_drv_no_such_file)
+          << Opts.DiagnosticSuppressionMappingsFile;
+    }
+  }
 }
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp b/clang/unittests/Basic/DiagnosticTest.cpp
index b26f72a2fb0ee5a..88fa1800f0ff2a4 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -346,4 +346,13 @@ TEST_F(SuppressionMappingTest, IsIgnored) {
   EXPECT_FALSE(Diags.isIgnored(diag::warn_unused_function,
                                SM.getLocForStartOfFile(ClangID)));
 }
+
+TEST_F(SuppressionMappingTest, ParsingRespectsOtherWarningOpts) {
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+              llvm::MemoryBuffer::getMemBuffer("[non-existing-warning]"));
+  Diags.getDiagnosticOptions().Warnings.push_back("no-unknown-warning-option");
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(diags(), IsEmpty());
+}
 } // namespace

@jyknight
Copy link
Member

jyknight commented Feb 5, 2025

(Oh, all these suppression mappings fixes will need to be backported to the 20.x branch too.)

We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.
@kadircet kadircet merged commit ecb016a into llvm:main Feb 6, 2025
4 of 6 checks passed
@kadircet kadircet added this to the LLVM 20.X Release milestone Feb 6, 2025
@kadircet
Copy link
Member Author

kadircet commented Feb 6, 2025

/cherry-pick ecb016a

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

/pull-request #126030

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 8, 2025
…llvm#125714)

We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.

(cherry picked from commit ecb016a)
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…llvm#125714)

We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

3 participants