[clang] [flang] [llvm] [mlir] [Support][mlir][llvm-mc] Match each verify directive once by default (PR #233308)

Alexander Richardson via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 6 08:52:44 PST 2026


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

>From 704ded3344cc41b25b91f20e6db7e8da259e5256 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Wed, 28 Oct 2026 11:12:54 -0700
Subject: [PATCH 1/4] [nspr] initial commit

---
 llvm/docs/CommandGuide/llvm-mc.md             |  3 +-
 .../Support/SourceMgrDiagnosticVerifier.h     |  8 +--
 .../Support/SourceMgrDiagnosticVerifier.cpp   | 49 ++++++++++++-------
 llvm/test/tools/llvm-mc/verify/basic.s        | 35 +++++++++++++
 mlir/docs/Diagnostics.md                      |  9 ++--
 .../Dialect/GPU/transform-gpu-failing.mlir    |  4 +-
 mlir/test/Dialect/Linalg/invalid.mlir         |  2 +-
 .../Dialect/Linalg/match-ops-interpreter.mlir |  4 +-
 .../Linalg/transform-op-specialize.mlir       |  2 +-
 mlir/test/Dialect/SCF/loop-pipelining.mlir    |  2 +-
 .../Transform/check-use-after-free.mlir       |  4 +-
 .../Dialect/Transform/expensive-checks.mlir   |  1 +
 .../test/Dialect/Transform/foreach-match.mlir |  6 +--
 .../Transform/multi-arg-top-level-values.mlir | 10 +---
 mlir/test/Dialect/Transform/ops-invalid.mlir  |  2 +-
 .../Dialect/Transform/test-interpreter.mlir   | 10 ++--
 mlir/test/IR/invalid-builtin-attributes.mlir  |  2 +-
 mlir/test/IR/test-verification-order.mlir     |  4 +-
 18 files changed, 102 insertions(+), 55 deletions(-)

diff --git a/llvm/docs/CommandGuide/llvm-mc.md b/llvm/docs/CommandGuide/llvm-mc.md
index 94b55a0586f405..66ca7d9dded211 100644
--- a/llvm/docs/CommandGuide/llvm-mc.md
+++ b/llvm/docs/CommandGuide/llvm-mc.md
@@ -169,7 +169,7 @@ Check diagnostics against directives in single-line comments instead of printing
 Directives have the form:
 
 ```text
-<prefix>-<kind>[-re][@<offset>] {{<text>}}
+<prefix>-<kind>[-re][@<offset>] [<count>] {{<text>}}
 ```
 
 - `<prefix>`: `expected` by default, or any prefix listed in the comma-separated `<prefixes>` argument.
@@ -180,6 +180,7 @@ Directives have the form:
   - `@+N` / `@-N`: `N` lines below or above the directive.
   - `@above` / `@below`: the nearest non-directive line above or below.
   - `@unknown`: a diagnostic with no source location.
+- `<count>`: the number of times the diagnostic is expected (defaults to 1).
 
 At most one directive is recognized per line.
 {program}`llvm-mc` succeeds if all directives are matched and no unexpected diagnostics are emitted.
diff --git a/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h b/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
index 120f8fef3fece7..750fbc8c93a9ab 100644
--- a/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
+++ b/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
@@ -32,7 +32,7 @@ class raw_ostream;
 /// Scans SourceMgr source buffers for 'expected-<kind>' comments (e.g.
 /// 'expected-error {{message}}') and verifies that the diagnostics reported
 /// to it via \c process match them, and that every expected diagnostic is
-/// matched at least once.
+/// matched the expected number of times.
 class LLVM_ABI SourceMgrDiagnosticVerifier {
 public:
   /// The result of matching a single actual diagnostic against the expected
@@ -76,8 +76,10 @@ class LLVM_ABI SourceMgrDiagnosticVerifier {
     unsigned lineNo;
     /// The location of the expected diagnostic within the input file.
     SMLoc fileLoc;
-    /// A flag indicating if the expected diagnostic has been matched yet.
-    bool matched = false;
+    /// The number of times this diagnostic is expected.
+    unsigned numExpected = 1;
+    /// The number of matching diagnostics seen so far.
+    unsigned numSeen = 0;
     /// The substring that is expected to be within the diagnostic.
     StringRef substring;
     /// An optional regex matcher, if the expected diagnostic substring was a
diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
index d6082ce369f435..89926a00867857 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -100,7 +100,8 @@ static Regex buildExpectedRegex(ArrayRef<StringRef> prefixes) {
       },
       [&] { pattern += '|'; });
   pattern += ")-(error|note|remark|warning)(-re)?"
-             "( *@([+-][0-9]+|above|below|unknown))? *{{(.*)}}$";
+             "( *@([+-][0-9]+|above|below|unknown))?"
+             "( +([0-9]+))? *{{(.*)}}$";
   return Regex(pattern);
 }
 
@@ -127,7 +128,7 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
   SmallVector<StringRef, 100> lines;
   buf->getBuffer().split(lines, '\n');
   for (unsigned lineNo = 0, e = lines.size(); lineNo < e; ++lineNo) {
-    SmallVector<StringRef, 8> matches;
+    SmallVector<StringRef, 10> matches;
     if (!expected.match(lines[lineNo].rtrim(), &matches)) {
       // Check for designators that apply to this line.
       if (!designatorsForNextLine.empty()) {
@@ -153,7 +154,7 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
       assert(matches[3] == "note");
       kind = SourceMgr::DK_Note;
     }
-    ExpectedDiag record(kind, lineNo + 1, expectedStart, matches[7]);
+    ExpectedDiag record(kind, lineNo + 1, expectedStart, matches[9]);
 
     // Check to see if this is a regex match, i.e. it includes the `-re`.
     if (!matches[4].empty() && !record.computeRegex(os, mgr)) {
@@ -161,6 +162,14 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
       continue;
     }
 
+    if (!matches[8].empty() &&
+        (matches[8].getAsInteger(10, record.numExpected) ||
+         record.numExpected == 0)) {
+      record.emitError(os, mgr, "invalid count '" + matches[8] + "'");
+      ok = false;
+      continue;
+    }
+
     StringRef offsetMatch = matches[6];
     if (!offsetMatch.empty()) {
       // Get the integer value without the @ and +/- prefix.
@@ -228,21 +237,19 @@ SourceMgrDiagnosticVerifier::process(raw_ostream &os, SourceMgr &mgr,
   // If we find something that is close then emit a more specific error.
   ExpectedDiag *nearMiss = nullptr;
 
-  // If this was an expected error, remember that we saw it and return.
   for (auto &e : diags) {
     // File line must match (unless it's an unknown location).
     if (hasLoc && e.lineNo != lineNo)
       continue;
-    if (e.match(message)) {
-      if (e.kind == kind) {
-        e.matched = true;
-        return MatchResult::Matched;
-      }
-
-      // If this only differs based on the diagnostic kind, then consider it
-      // to be a near miss.
-      nearMiss = &e;
+    if (e.numSeen == e.numExpected || !e.match(message))
+      continue;
+    if (e.kind == kind) {
+      ++e.numSeen;
+      return MatchResult::Matched;
     }
+    // If this only differs based on the diagnostic kind, then consider it
+    // to be a near miss.
+    nearMiss = &e;
   }
 
   if (!reportUnexpected)
@@ -264,12 +271,18 @@ SourceMgrDiagnosticVerifier::process(raw_ostream &os, SourceMgr &mgr,
 bool SourceMgrDiagnosticVerifier::verify(raw_ostream &os, SourceMgr &mgr) {
   // Verify that all expected errors were seen.
   auto checkExpectedDiags = [&](ExpectedDiag &diag) {
-    if (!diag.matched) {
+    if (diag.numSeen == diag.numExpected)
+      return;
+    std::string expectedMsg = ("expected " + getDiagKindStr(diag.kind) + " \"" +
+                               diag.substring + "\"")
+                                  .str();
+    if (diag.numExpected == 1)
+      diag.emitError(os, mgr, expectedMsg + " was not produced");
+    else
       diag.emitError(os, mgr,
-                     "expected " + getDiagKindStr(diag.kind) + " \"" +
-                         diag.substring + "\" was not produced");
-      ok = false;
-    }
+                     expectedMsg + " was produced " + Twine(diag.numSeen) +
+                         " of " + Twine(diag.numExpected) + " times");
+    ok = false;
   };
   for (auto &expectedDiagsPair : expectedDiagsPerFile)
     for (auto &diag : expectedDiagsPair.second)
diff --git a/llvm/test/tools/llvm-mc/verify/basic.s b/llvm/test/tools/llvm-mc/verify/basic.s
index 237a9377bd8a25..97cb46daedc1fe 100644
--- a/llvm/test/tools/llvm-mc/verify/basic.s
+++ b/llvm/test/tools/llvm-mc/verify/basic.s
@@ -29,6 +29,19 @@
 .qux_directive # expected-error {{unknown directive}}
 .quux_directive // expected-error {{unknown directive}}
 
+## A diagnostic that is reported twice on a line needs two directives or a count.
+.dup_directive; .dup_directive
+# expected-error at -1 {{unknown directive}}
+# expected-error at -2 {{unknown directive}}
+.dup_directive; .dup_directive
+# expected-error at -1 2 {{unknown directive}}
+
+## A directive that was already matched does not steal a later diagnostic from
+## a second directive on the same line.
+movl $1, %eax, %ebx; movl $1, %eax, %ebx
+# expected-error at -1 {{operand}}
+# expected-error at -2 {{invalid operand}}
+
 movl $1, %eax, %ebx
 # expected-error at -1 {{invalid operand for instruction}}
 
@@ -85,6 +98,28 @@ nop
 # expected-error at -1 {{this will never happen}}
 # CHECK: error: expected error "this will never happen" was not produced
 
+#--- duplicate.s
+## Each directive matches only one diagnostic, and an already-matched
+## directive is not reported as a near miss for a later diagnostic.
+# RUN: not llvm-mc --triple=x86_64 --verify duplicate.s 2>&1 \
+# RUN:   | FileCheck duplicate.s --implicit-check-not=error:
+.dup_directive; .dup_directive
+# expected-error at -1 {{unknown directive}}
+# CHECK: duplicate.s:[[#@LINE-2]]:17: error: unexpected error: unknown directive
+.foo_directive; .warning "unknown directive"
+# expected-error at -1 {{unknown directive}}
+# CHECK: duplicate.s:[[#@LINE-2]]:17: error: unexpected warning: unknown directive
+
+#--- too-few.s
+## Directives with an invalid count or a count that is matched fewer times fail.
+# RUN: not llvm-mc --triple=x86_64 --verify too-few.s 2>&1 \
+# RUN:   | FileCheck too-few.s --implicit-check-not=error:
+.foo_directive
+# expected-error at -1 2 {{unknown directive}}
+# expected-warning at -2 0 {{zero count}}
+# CHECK: too-few.s:[[#@LINE-1]]:3: error: invalid count '0'
+# CHECK: too-few.s:[[#@LINE-3]]:3: error: expected error "unknown directive" was produced 1 of 2 times
+
 #--- no-diagnostics.s
 ## A file without diagnostics or directives passes.
 # RUN: llvm-mc --triple=x86_64 --verify no-diagnostics.s
diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md
index c9d3692f427dce..d8a399985f4f0f 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -318,15 +318,16 @@ This handler is a wrapper around a llvm::SourceMgr that is used to verify that
 certain diagnostics have been emitted to the context. To use this handler,
 annotate your source file with expected diagnostics in the form of:
 
-*   `expected-(error|note|remark|warning)(-re)? {{ message }}`
+*   `expected-(error|note|remark|warning)(-re)?(@([+-][0-9]+|above|below|unknown))?( [0-9]+)? {{ message }}`
 
 The provided `message` is a string expected to be contained within the generated
 diagnostic. The `-re` suffix may be used to enable regex matching within the
 `message`. When present, the `message` may define regex match sequences within
 `{{` `}}` blocks. The regular expression matcher supports Extended POSIX regular
-expressions (ERE). `expected-` must not be preceded by an alphanumeric
-character, hyphen, or underscore (so e.g. `unexpected-error` is ignored). A few
-examples are shown below:
+expressions (ERE). An optional positive integer count before `{{` specifies how
+many diagnostics the directive must match (default: 1). `expected-` must not be
+preceded by an alphanumeric character, hyphen, or underscore (so e.g.
+`unexpected-error` is ignored). A few examples are shown below:
 
 ```mlir
 // Expect an error on the same line.
diff --git a/mlir/test/Dialect/GPU/transform-gpu-failing.mlir b/mlir/test/Dialect/GPU/transform-gpu-failing.mlir
index 099283826cee02..aa0b3c1c7a7cb8 100644
--- a/mlir/test/Dialect/GPU/transform-gpu-failing.mlir
+++ b/mlir/test/Dialect/GPU/transform-gpu-failing.mlir
@@ -50,8 +50,8 @@ func.func @map_nested_forall_to_threads_excessive_threads(%x: memref<2 x 32 x f3
 module attributes {transform.with_named_sequence} {
   transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
     %funcop = transform.structured.match ops{["gpu.launch"]} in %arg0 : (!transform.any_op) -> !transform.any_op
-    // expected-error @below {{Trying to launch a GPU kernel with grid_dims = (1, 1, 1) block_dims = (1200, 9, 1). It is larger than the limits.}}
-    // expected-note @below {{"block_dims" is too large}}
+    // expected-error @below 2 {{Trying to launch a GPU kernel with grid_dims = (1, 1, 1) block_dims = (1200, 9, 1). It is larger than the limits.}}
+    // expected-note @below 2 {{"block_dims" is too large}}
     transform.gpu.map_nested_forall_to_threads %funcop block_dims = [1200, 9, 1] : (!transform.any_op) -> !transform.any_op
     transform.yield
   }
diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index 581728e412d73f..397859aee16b93 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -2426,7 +2426,7 @@ func.func @pooling_nwc_min_unsigned_i1(
 func.func @matmul_invalid_mixed_types(%t: tensor<?xf16>, %f: vector<4xf16>)
   -> (tensor<?xf16>, vector<4xf16>)
 {
-  // expected-warning @unknown {{could not cast operand of type 'f16' to 'vector<4xf16>'}}
+  // expected-warning @unknown 2 {{could not cast operand of type 'f16' to 'vector<4xf16>'}}
   // expected-error @below {{Cannot build binary Linalg operation: expects allComplex, allFloatingPoint, or allInteger, got 'vector<4xf16>' and 'f16'}}
   %0 = linalg.matmul ins(%t, %t : tensor<?xf16>, tensor<?xf16>)
                                 outs(%f : vector<4xf16>) -> tensor<?xf16>
diff --git a/mlir/test/Dialect/Linalg/match-ops-interpreter.mlir b/mlir/test/Dialect/Linalg/match-ops-interpreter.mlir
index 0d60e5e5655dd9..47879d9485f59b 100644
--- a/mlir/test/Dialect/Linalg/match-ops-interpreter.mlir
+++ b/mlir/test/Dialect/Linalg/match-ops-interpreter.mlir
@@ -546,7 +546,7 @@ module attributes { transform.with_named_sequence } {
   func.func @payload(%f32: f32,
             // expected-remark @below {{output 0}}
             // expected-remark @below {{all output}}
-            // expected-note @below {{value handle points to a block argument #1 in block #0 in region #0}}
+            // expected-note @below 2 {{value handle points to a block argument #1 in block #0 in region #0}}
             %tf32: tensor<?xf32>,
             // expected-remark @below {{all output}}
             // expected-note @below {{value handle points to a block argument #2 in block #0 in region #0}}
@@ -555,7 +555,7 @@ module attributes { transform.with_named_sequence } {
     // expected-remark @below {{output 0}}
     // expected-remark @below {{output producer}}
     // expected-remark @below {{all output}}
-    // expected-note @below {{value handle points to an op result #0}}
+    // expected-note @below 2 {{value handle points to an op result #0}}
     %0 = linalg.fill ins(%f32: f32) outs(%tf32: tensor<?xf32>) -> tensor<?xf32>
 
     linalg.generic {
diff --git a/mlir/test/Dialect/Linalg/transform-op-specialize.mlir b/mlir/test/Dialect/Linalg/transform-op-specialize.mlir
index 8ede2e0add10ba..0f5a7c5485d244 100644
--- a/mlir/test/Dialect/Linalg/transform-op-specialize.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-specialize.mlir
@@ -58,7 +58,7 @@ func.func @copy_with_down_cast(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf16>) {
 module attributes {transform.with_named_sequence} {
   transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
     %0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
-    // expected-error @below {{failed to apply}}
+    // expected-error @below 4 {{failed to apply}}
     %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op
     transform.yield
   }
diff --git a/mlir/test/Dialect/SCF/loop-pipelining.mlir b/mlir/test/Dialect/SCF/loop-pipelining.mlir
index 99f8d84a6af2ec..5d36dff262be78 100644
--- a/mlir/test/Dialect/SCF/loop-pipelining.mlir
+++ b/mlir/test/Dialect/SCF/loop-pipelining.mlir
@@ -990,7 +990,7 @@ func.func @invalid_schedule2(%A: memref<?xf32>, %result: memref<?xf32>) {
   %c4 = arith.constant 4 : index
   %cf = arith.constant 1.0 : f32
   %r = scf.for %i0 = %c0 to %c4 step %c1 iter_args(%idx = %c0) -> (index) {
-    // expected-error at +1 {{operation scheduled before its operands}}
+    // expected-error at +1 2 {{operation scheduled before its operands}}
     %A_elem = memref.load %A[%idx] { __test_pipelining_stage__ = 0, __test_pipelining_op_order__ = 0 } : memref<?xf32>
     %idx1 = arith.addi %idx, %c1 { __test_pipelining_stage__ = 1, __test_pipelining_op_order__ = 1 } : index
     memref.store %A_elem, %result[%idx] { __test_pipelining_stage__ = 2, __test_pipelining_op_order__ = 2 } : memref<?xf32>
diff --git a/mlir/test/Dialect/Transform/check-use-after-free.mlir b/mlir/test/Dialect/Transform/check-use-after-free.mlir
index 6c196e425a40a4..8896d49ba651db 100644
--- a/mlir/test/Dialect/Transform/check-use-after-free.mlir
+++ b/mlir/test/Dialect/Transform/check-use-after-free.mlir
@@ -117,7 +117,7 @@ func.func @use_after_free() {
 // precede the one that frees it in the same block. Both operations should
 // be reported as use-after-free.
 func.func @use_after_free_self_cycle() {
-  // expected-note @below {{allocated here}}
+  // expected-note @below 2 {{allocated here}}
   %0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
   transform.test_transform_op_with_regions {
     "transform.test_branching_transform_op_terminator"() : () -> ()
@@ -131,7 +131,7 @@ func.func @use_after_free_self_cycle() {
     ^bb0(%arg0: !transform.any_op):
     }
     // expected-warning @below {{operand #0 may be used after free}}
-    // expected-note @below {{freed here}}
+    // expected-note @below 2 {{freed here}}
     transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
     "transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
   ^bb2:
diff --git a/mlir/test/Dialect/Transform/expensive-checks.mlir b/mlir/test/Dialect/Transform/expensive-checks.mlir
index 397e988f62364b..03d01ff679677c 100644
--- a/mlir/test/Dialect/Transform/expensive-checks.mlir
+++ b/mlir/test/Dialect/Transform/expensive-checks.mlir
@@ -436,6 +436,7 @@ module attributes {transform.with_named_sequence}  {
 module attributes {transform.with_named_sequence}  {
   transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
     // expected-note @below {{payload op}}
+    // expected-note @below {{nested payload op}}
     // expected-note @below {{handle to invalidated ops}}
     %0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
     transform.test_re_enter_region {
diff --git a/mlir/test/Dialect/Transform/foreach-match.mlir b/mlir/test/Dialect/Transform/foreach-match.mlir
index a7cd8e9ff543ee..e5208fa18d98ed 100644
--- a/mlir/test/Dialect/Transform/foreach-match.mlir
+++ b/mlir/test/Dialect/Transform/foreach-match.mlir
@@ -81,9 +81,9 @@ module attributes { transform.with_named_sequence } {
 
 // -----
 
-// expected-remark @below {{op from within the matcher}}
+// expected-remark @below 2 {{op from within the matcher}}
 module attributes { transform.with_named_sequence } {
-  // expected-remark @below {{returned root}}
+  // expected-remark @below 2 {{returned root}}
   func.func @foo() {
     return
   }
@@ -101,7 +101,7 @@ module attributes { transform.with_named_sequence } {
       %root: !transform.any_op {transform.readonly},
       %param: !transform.param<i64> {transform.readonly}) -> (!transform.any_op, !transform.param<i64>) {
     transform.debug.emit_remark_at %root, "op from within the matcher" : !transform.any_op
-    // expected-remark @below {{param from within the matcher 42}}
+    // expected-remark @below 2 {{param from within the matcher 42}}
     transform.debug.emit_param_as_remark %param, "param from within the matcher" : !transform.param<i64>
     transform.yield %root, %param : !transform.any_op, !transform.param<i64>
   }
diff --git a/mlir/test/Dialect/Transform/multi-arg-top-level-values.mlir b/mlir/test/Dialect/Transform/multi-arg-top-level-values.mlir
index dcc1079267dc7c..b154f48e6940c4 100644
--- a/mlir/test/Dialect/Transform/multi-arg-top-level-values.mlir
+++ b/mlir/test/Dialect/Transform/multi-arg-top-level-values.mlir
@@ -2,10 +2,7 @@
 // RUN:     debug-bind-trailing-args=^test.some_returning_op,^test.some_other_returning_op})' \
 // RUN:             --split-input-file --verify-diagnostics
 
-// Note that diagnostic checker will merge two diagnostics with the same message
-// at the same location, so only check the remark once.
-// 
-// expected-remark @below {{first extra}}
+// expected-remark @below 2 {{first extra}}
 // expected-note @below {{value handle points to an op result #0}}
 // expected-note @below {{value handle points to an op result #1}}
 %0:2 = "test.some_returning_op"() : () -> (i32, i64)
@@ -14,10 +11,7 @@
 // expected-note @below {{value handle points to an op result #0}}
 %1 = "test.some_returning_op"() : () -> index
 
-// Note that diagnostic checker will merge two diagnostics with the same message
-// at the same location, so only check the remark once.
-// 
-// expected-remark @below {{second extra}}
+// expected-remark @below 2 {{second extra}}
 // expected-note @below {{value handle points to an op result #0}}
 // expected-note @below {{value handle points to an op result #1}}
 %2:2 = "test.some_other_returning_op"() : () -> (f32, f64)
diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index a5449580f0feb4..f962e9edad4403 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -591,7 +591,7 @@ module attributes { transform.with_named_sequence } {
   // Note that printing a warning doesn't result in verification failures, so this
   // also checks for the IR being printed back.
   // CHECK-LABEL: transform.named_sequence @emit_warning_only
-  // expected-warning @below {{argument #0 is not consumed in the body but is marked as consume}}
+  // expected-warning @below 2 {{argument #0 is not consumed in the body but is marked as consume}}
   transform.named_sequence @emit_warning_only(%op: !transform.any_op {transform.consumed}) {
     transform.debug.emit_remark_at %op, "message" : !transform.any_op
     transform.yield
diff --git a/mlir/test/Dialect/Transform/test-interpreter.mlir b/mlir/test/Dialect/Transform/test-interpreter.mlir
index e05b7024e38762..d0bba4980e01be 100644
--- a/mlir/test/Dialect/Transform/test-interpreter.mlir
+++ b/mlir/test/Dialect/Transform/test-interpreter.mlir
@@ -105,7 +105,7 @@ func.func @foo() {
   return
 }
 
-// expected-remark @below {{parent function}}
+// expected-remark @below 2 {{parent function}}
 func.func @bar() {
   %0 = arith.constant 0 : i32
   %1 = arith.constant 1 : i32
@@ -818,7 +818,7 @@ module attributes {transform.with_named_sequence} {
         transform.foreach %f : !transform.any_op {
         ^bb2(%arg2: !transform.any_op):
           %p = transform.num_associations %arg2 : (!transform.any_op) -> !transform.param<i64>
-          // expected-remark @below {{1}}
+          // expected-remark @below 2 {{1}}
           transform.debug.emit_param_as_remark  %p : !transform.param<i64>
           transform.debug.emit_remark_at %arg2, "transform applied" : !transform.any_op
         }
@@ -930,7 +930,7 @@ module attributes {transform.with_named_sequence} {
     %f = transform.structured.match ops{["arith.constant"]} in %arg1 : (!transform.any_op) -> !transform.any_op
     transform.foreach %f : !transform.any_op {
     ^bb2(%arg2: !transform.any_op):
-      // expected-remark @below {{erasing}}
+      // expected-remark @below 4 {{erasing}}
       transform.test_emit_remark_and_erase_operand %arg2, "erasing" : !transform.any_op
     }
     transform.yield
@@ -2349,9 +2349,9 @@ module attributes {transform.with_named_sequence} {
 // -----
 
 func.func @get_parent_op() {
-  // expected-remark @below{{found test.foo parent}}
+  // expected-remark @below 2 {{found test.foo parent}}
   "test.foo"() ({
-    // expected-remark @below{{direct parent}}
+    // expected-remark @below 2 {{direct parent}}
     "test.bar"() ({
       "test.qux"() : () -> ()
       "test.qux"() : () -> ()
diff --git a/mlir/test/IR/invalid-builtin-attributes.mlir b/mlir/test/IR/invalid-builtin-attributes.mlir
index 2a64a6b697baa4..46efc7772cdaf8 100644
--- a/mlir/test/IR/invalid-builtin-attributes.mlir
+++ b/mlir/test/IR/invalid-builtin-attributes.mlir
@@ -615,7 +615,7 @@ func.func @duplicate_dictionary_attr_key() {
 
 // -----
 
-// expected-error at below {{expected attribute}}
+// expected-error at below 2 {{expected attribute}}
 #attr = distinct[8]<attribute
 
 // -----
diff --git a/mlir/test/IR/test-verification-order.mlir b/mlir/test/IR/test-verification-order.mlir
index d6d4c3acaf7e3b..208c85812e3457 100644
--- a/mlir/test/IR/test-verification-order.mlir
+++ b/mlir/test/IR/test-verification-order.mlir
@@ -45,9 +45,9 @@ func.func @verify_nested_isolated_above() {
   "test.verifiers"(%0) ({
     // expected-remark at -1 {{success run of region verifier}}
     %1 = arith.constant 2 : i32
-    // expected-remark at +1 {{success run of verifier}}
+    // expected-remark at +1 2 {{success run of verifier}}
     "test.verifiers"(%1) ({
-      // expected-remark at -1 {{success run of region verifier}}
+      // expected-remark at -1 2 {{success run of region verifier}}
       %2 = arith.constant 3 : index
     }) : (i32) -> ()
   }) : (i32) -> ()

>From d77268a3bc67a8807ffed1a54b9021087bc405d0 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Wed, 28 Oct 2026 17:13:38 -0700
Subject: [PATCH 2/4] [nspr] update

---
 clang/test/CIR/IR/invalid-vtable.cir                   | 2 +-
 flang/test/Transforms/generic-loop-rewriting-todo.mlir | 2 +-
 mlir/test/Examples/transform/Ch1/invalidation-1.mlir   | 2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/test/CIR/IR/invalid-vtable.cir b/clang/test/CIR/IR/invalid-vtable.cir
index f444a0ee5b539d..302e14cdd3abc3 100644
--- a/clang/test/CIR/IR/invalid-vtable.cir
+++ b/clang/test/CIR/IR/invalid-vtable.cir
@@ -60,7 +60,7 @@ module {
 !u64i = !cir.int<u, 64>
 !rec_anon_struct = !cir.struct<{data !cir.array<!u64i x 4>}>
 module {
-  // expected-error @below {{expected GlobalViewAttr or ConstPtrAttr}}
+  // expected-error @below 3 {{expected GlobalViewAttr or ConstPtrAttr}}
   cir.global external @_ZTV1S = #cir.vtable<{#cir.const_array<[#cir.int<1> : !u64i, #cir.int<1> : !u64i, #cir.int<3> : !u64i, #cir.int<4> : !u64i]> : !cir.array<!u64i x 4>}> : !rec_anon_struct align(8)
   cir.func private dso_local @_ZN1S3keyEv(%arg0: !cir.ptr<!rec_S>)
   cir.func private dso_local @_ZN1S6nonKeyEv(%arg0: !cir.ptr<!rec_S>)
diff --git a/flang/test/Transforms/generic-loop-rewriting-todo.mlir b/flang/test/Transforms/generic-loop-rewriting-todo.mlir
index 64094d61eb9a36..0b6b31feb4fb42 100644
--- a/flang/test/Transforms/generic-loop-rewriting-todo.mlir
+++ b/flang/test/Transforms/generic-loop-rewriting-todo.mlir
@@ -5,7 +5,7 @@ func.func @_QPloop_order() {
     %c10 = arith.constant 10 : i32
     %c1 = arith.constant 1 : i32
 
-    // expected-error at below {{not yet implemented: Unhandled clause order in omp.loop operation}}
+    // expected-error at below 2 {{not yet implemented: Unhandled clause order in omp.loop operation}}
     omp.loop order(reproducible:concurrent) {
       omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
         omp.yield
diff --git a/mlir/test/Examples/transform/Ch1/invalidation-1.mlir b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
index 6f2257c360e07e..0579b6e8df0190 100644
--- a/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
+++ b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
@@ -34,6 +34,7 @@ func.func @fc_relu(%lhs: tensor<512x512xf32>, %rhs: tensor<512x512xf32>,
                    %bias: tensor<512x512xf32>, %output: tensor<512x512xf32>)
                    -> tensor<512x512xf32> {
   // Matrix-matrix multiplication.
+  // expected-note @below {{nested payload op}}
   // expected-note @below {{payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
@@ -83,6 +84,7 @@ func.func @fc_relu(%lhs: tensor<512x512xf32>, %rhs: tensor<512x512xf32>,
                    %bias: tensor<512x512xf32>, %output: tensor<512x512xf32>)
                    -> tensor<512x512xf32> {
   // Matrix-matrix multiplication.
+  // expected-note @below {{nested payload op}}
   // expected-note @below {{payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>

>From 1a254df3ff7090d6cf4a5128e9cacf89fae520af Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Mon, 2 Nov 2026 22:10:59 -0800
Subject: [PATCH 3/4] [nspr] update

---
 mlir/test/Dialect/Transform/expensive-checks.mlir    | 2 +-
 mlir/test/Examples/transform/Ch1/invalidation-1.mlir | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/test/Dialect/Transform/expensive-checks.mlir b/mlir/test/Dialect/Transform/expensive-checks.mlir
index 03d01ff679677c..3b7cd6d72b9d65 100644
--- a/mlir/test/Dialect/Transform/expensive-checks.mlir
+++ b/mlir/test/Dialect/Transform/expensive-checks.mlir
@@ -435,7 +435,7 @@ module attributes {transform.with_named_sequence}  {
 // Consuming the same handle repeatedly in the region should trigger an error.
 module attributes {transform.with_named_sequence}  {
   transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
-    // expected-note @below {{payload op}}
+    // expected-note @below {{ancestor payload op}}
     // expected-note @below {{nested payload op}}
     // expected-note @below {{handle to invalidated ops}}
     %0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
diff --git a/mlir/test/Examples/transform/Ch1/invalidation-1.mlir b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
index 0579b6e8df0190..8a10b3512c38dd 100644
--- a/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
+++ b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
@@ -34,8 +34,8 @@ func.func @fc_relu(%lhs: tensor<512x512xf32>, %rhs: tensor<512x512xf32>,
                    %bias: tensor<512x512xf32>, %output: tensor<512x512xf32>)
                    -> tensor<512x512xf32> {
   // Matrix-matrix multiplication.
+  // expected-note @below {{ancestor payload op}}
   // expected-note @below {{nested payload op}}
-  // expected-note @below {{payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
 
@@ -84,8 +84,8 @@ func.func @fc_relu(%lhs: tensor<512x512xf32>, %rhs: tensor<512x512xf32>,
                    %bias: tensor<512x512xf32>, %output: tensor<512x512xf32>)
                    -> tensor<512x512xf32> {
   // Matrix-matrix multiplication.
+  // expected-note @below {{ancestor payload op}}
   // expected-note @below {{nested payload op}}
-  // expected-note @below {{payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
 

>From 57a4ca7da93d712ebce8461fe435cd6b57b4eae8 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Tue, 3 Nov 2026 14:12:33 -0800
Subject: [PATCH 4/4] [nspr] update

---
 clang/test/CIR/IR/invalid-vtable.cir         |  2 +-
 mlir/docs/Diagnostics.md                     |  9 +++++----
 mlir/test/Dialect/OpenMP/memory-effects.mlir | 12 ++++++------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/test/CIR/IR/invalid-vtable.cir b/clang/test/CIR/IR/invalid-vtable.cir
index 302e14cdd3abc3..53816f71b8a000 100644
--- a/clang/test/CIR/IR/invalid-vtable.cir
+++ b/clang/test/CIR/IR/invalid-vtable.cir
@@ -60,7 +60,7 @@ module {
 !u64i = !cir.int<u, 64>
 !rec_anon_struct = !cir.struct<{data !cir.array<!u64i x 4>}>
 module {
-  // expected-error @below 3 {{expected GlobalViewAttr or ConstPtrAttr}}
+  // expected-error @below 4 {{expected GlobalViewAttr or ConstPtrAttr}}
   cir.global external @_ZTV1S = #cir.vtable<{#cir.const_array<[#cir.int<1> : !u64i, #cir.int<1> : !u64i, #cir.int<3> : !u64i, #cir.int<4> : !u64i]> : !cir.array<!u64i x 4>}> : !rec_anon_struct align(8)
   cir.func private dso_local @_ZN1S3keyEv(%arg0: !cir.ptr<!rec_S>)
   cir.func private dso_local @_ZN1S6nonKeyEv(%arg0: !cir.ptr<!rec_S>)
diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md
index d8a399985f4f0f..ecc6f3f18564fa 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -324,10 +324,11 @@ The provided `message` is a string expected to be contained within the generated
 diagnostic. The `-re` suffix may be used to enable regex matching within the
 `message`. When present, the `message` may define regex match sequences within
 `{{` `}}` blocks. The regular expression matcher supports Extended POSIX regular
-expressions (ERE). An optional positive integer count before `{{` specifies how
-many diagnostics the directive must match (default: 1). `expected-` must not be
-preceded by an alphanumeric character, hyphen, or underscore (so e.g.
-`unexpected-error` is ignored). A few examples are shown below:
+expressions (ERE).
+An optional positive integer count before `{{` specifies how many diagnostics the directive must match (default: 1).
+`expected-` must not be preceded by an alphanumeric
+character, hyphen, or underscore (so e.g. `unexpected-error` is ignored). A few
+examples are shown below:
 
 ```mlir
 // Expect an error on the same line.
diff --git a/mlir/test/Dialect/OpenMP/memory-effects.mlir b/mlir/test/Dialect/OpenMP/memory-effects.mlir
index 00ac885c9181d4..41109f4482ad81 100644
--- a/mlir/test/Dialect/OpenMP/memory-effects.mlir
+++ b/mlir/test/Dialect/OpenMP/memory-effects.mlir
@@ -110,8 +110,8 @@ func.func @sections_bounded_reduction_effects(%x: memref<f32>) {
 func.func @sections_unbounded_reduction_effects(%x: memref<f32>) {
   // Without the flag, even a pure recipe is modeled with arbitrary effects.
   // expected-remark at below {{recursive memory effects}}
-  // expected-remark at below {{found an instance of 'read' on resource '<Default>'}}
-  // expected-remark at below {{found an instance of 'write' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'read' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'write' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'allocate' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'free' on resource '<Default>'}}
   omp.sections nowait reduction(@add_f32 %x -> %p : memref<f32>) {
@@ -123,8 +123,8 @@ func.func @sections_unbounded_reduction_effects(%x: memref<f32>) {
 func.func @sections_bounded_private_unbounded_reduction(%x: memref<i32>, %y: memref<f32>) {
   // A bounded private clause does not constrain an unbounded reduction clause.
   // expected-remark at below {{recursive memory effects}}
-  // expected-remark at below {{found an instance of 'read' on resource '<Default>'}}
-  // expected-remark at below {{found an instance of 'write' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'read' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'write' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'allocate' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'free' on resource '<Default>'}}
   omp.sections nowait private(@private_i32 %x -> %px : memref<i32>)
@@ -137,8 +137,8 @@ func.func @sections_bounded_private_unbounded_reduction(%x: memref<i32>, %y: mem
 func.func @sections_unbounded_private_bounded_reduction(%x: memref<i32>, %y: memref<f32>) {
   // A bounded reduction clause does not constrain an unbounded private clause.
   // expected-remark at below {{recursive memory effects}}
-  // expected-remark at below {{found an instance of 'read' on resource '<Default>'}}
-  // expected-remark at below {{found an instance of 'write' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'read' on resource '<Default>'}}
+  // expected-remark at below 2 {{found an instance of 'write' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'allocate' on resource '<Default>'}}
   // expected-remark at below {{found an instance of 'free' on resource '<Default>'}}
   omp.sections nowait private(@private_i32 %x -> %px : memref<i32>)



More information about the cfe-commits mailing list