https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/233307

>From a3d752ed36c871737d836d66191c5e063413e9e9 Mon Sep 17 00:00:00 2001
From: Alex Richardson <[email protected]>
Date: Wed, 28 Oct 2026 11:11:46 -0700
Subject: [PATCH] [nspr] initial commit

---
 .../lib/Support/SourceMgrDiagnosticVerifier.cpp | 17 +++++++++++------
 llvm/test/tools/llvm-mc/verify/include.s        |  5 +++--
 llvm/tools/llvm-mc/llvm-mc.cpp                  |  4 ----
 mlir/lib/IR/Diagnostics.cpp                     |  6 ------
 4 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp 
b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
index d7dac0ed49793c..864c3d35110d81 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -243,6 +243,10 @@ SourceMgrDiagnosticVerifier::process(raw_ostream &os, 
SourceMgr &mgr,
     // with a location in an unknown file can never match anything.
     diags = computeExpectedDiags(os, mgr, buf);
   } else {
+    // '@unknown' directives may be in any buffer, including ones added after
+    // the verifier was created.
+    for (unsigned i = 0, e = mgr.getNumBuffers(); i != e; ++i)
+      (void)computeExpectedDiags(os, mgr, mgr.getMemoryBuffer(i + 1));
     diags = expectedUnknownLocDiags;
   }
 
@@ -297,17 +301,18 @@ bool SourceMgrDiagnosticVerifier::verify(raw_ostream &os, 
SourceMgr &mgr) {
                          " of " + Twine(diag.numExpected) + " times");
     ok = false;
   };
-  // Check buffers in registration order so that the output is deterministic.
+  // Check all buffers in registration order, including ones that were added
+  // after the verifier was created and had no diagnostics (e.g. included
+  // files). Clear the lists rather than the map so that calling verify()
+  // again does not rescan the buffers and report their directives again.
   for (unsigned i = 0, e = mgr.getNumBuffers(); i != e; ++i) {
-    auto it = expectedDiagsPerBuffer.find(mgr.getMemoryBuffer(i + 1));
-    if (it == expectedDiagsPerBuffer.end())
-      continue;
-    for (auto &diag : it->second)
+    const MemoryBuffer *buf = mgr.getMemoryBuffer(i + 1);
+    for (auto &diag : computeExpectedDiags(os, mgr, buf))
       checkExpectedDiags(diag);
+    expectedDiagsPerBuffer[buf].clear();
   }
   for (auto &diag : expectedUnknownLocDiags)
     checkExpectedDiags(diag);
-  expectedDiagsPerBuffer.clear();
   expectedUnknownLocDiags.clear();
   return ok;
 }
diff --git a/llvm/test/tools/llvm-mc/verify/include.s 
b/llvm/test/tools/llvm-mc/verify/include.s
index 40a31e40367d34..95d06baa04451b 100644
--- a/llvm/test/tools/llvm-mc/verify/include.s
+++ b/llvm/test/tools/llvm-mc/verify/include.s
@@ -3,8 +3,8 @@
 
 # REQUIRES: x86-registered-target
 # RUN: rm -rf %t && split-file %s %t && cd %t
-## FIXME: inc.s is never scanned since it has no diagnostics.
-# RUN: llvm-mc --triple=x86_64 --verify main.s
+# RUN: not llvm-mc --triple=x86_64 --verify main.s 2>&1 \
+# RUN:   | FileCheck inc.s --implicit-check-not=error:
 
 #--- main.s
 .include "inc.s"
@@ -12,3 +12,4 @@
 #--- inc.s
 nop
 # expected-error@-1 {{this will never happen}}
+# CHECK: inc.s:2:3: error: expected error "this will never happen" was not 
produced
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index b0dd1d9ad60f8a..363c43a2b2f030 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -541,10 +541,6 @@ int main(int argc, char **argv) {
   std::optional<SourceMgrDiagnosticVerifier> Verifier;
   if (!VerifyPrefixes.empty()) {
     Verifier.emplace(VerifyPrefixes);
-    // Scan the input up front so that its directives are checked even if it
-    // produces no diagnostics.
-    (void)Verifier->computeExpectedDiags(errs(), SrcMgr,
-                                         SrcMgr.getMemoryBuffer(1));
     // Most diagnostics are reported through SrcMgr, but some (e.g. from the
     // CFI checker) are only reported through Ctx, so route both to Ctx.
     Ctx.setDiagnosticHandler([&](const SMDiagnostic &Diag, bool,
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 1e0a6aca7f19d5..b4348043492670 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -673,12 +673,6 @@ 
SourceMgrDiagnosticVerifierHandler::SourceMgrDiagnosticVerifierHandler(
     llvm::SourceMgr &srcMgr, MLIRContext *ctx, raw_ostream &out, Level level)
     : SourceMgrDiagnosticHandler(srcMgr, ctx, out),
       impl(new SourceMgrDiagnosticVerifierHandlerImpl(level)) {
-  // Compute the expected diagnostics for each of the current files in the
-  // source manager.
-  for (unsigned i = 0, e = mgr.getNumBuffers(); i != e; ++i)
-    (void)impl->verifier.computeExpectedDiags(out, mgr,
-                                              mgr.getMemoryBuffer(i + 1));
-
   // The base class registered a handler that prints every diagnostic. The
   // verifier takes its place: it consumes diagnostics and reports unexpected
   // ones itself.

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to