https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/233307
>From c831fbb51b7771db5bdc25641f0f71eaebb38f6f Mon Sep 17 00:00:00 2001 From: Alex Richardson <[email protected]> Date: Wed, 28 Oct 2026 11:11:46 -0700 Subject: [PATCH 1/2] [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 29dcdb91f21d5f..4f4dad7e197ba7 100644 --- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp +++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp @@ -254,6 +254,10 @@ SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process( // 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; } @@ -310,17 +314,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 a6f28978099057..e089d67fd9a46a 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -539,10 +539,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 d55ba17afaaa18..1f7e162b13d18c 100644 --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -677,12 +677,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. >From ab086eae27d8f8a667b377f9eac25cc9f82d355e Mon Sep 17 00:00:00 2001 From: Alex Richardson <[email protected]> Date: Fri, 6 Nov 2026 15:21:06 -0800 Subject: [PATCH 2/2] restack --- llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp index 4f4dad7e197ba7..8b212cba5ef488 100644 --- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp +++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp @@ -254,8 +254,8 @@ SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process( // 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. + // A locationless diagnostic can match an '@unknown' directive written in + // any buffer, so scan all buffers to populate expectedUnknownLocDiags. for (unsigned i = 0, e = mgr.getNumBuffers(); i != e; ++i) (void)computeExpectedDiags(os, mgr, mgr.getMemoryBuffer(i + 1)); diags = expectedUnknownLocDiags; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
