[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 16:03:45 PST 2026


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

>From 684aa609999bfd50494334f2299e5fff7ba82097 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Fri, 6 Nov 2026 15:21:54 -0800
Subject: [PATCH] [nspr] initial commit

---
 clang/test/CIR/IR/invalid-vtable.cir          |  2 +-
 .../generic-loop-rewriting-todo.mlir          |  2 +-
 llvm/docs/CommandGuide/llvm-mc.md             |  3 +-
 .../Support/SourceMgrDiagnosticVerifier.h     |  8 ++--
 .../Support/SourceMgrDiagnosticVerifier.cpp   | 48 ++++++++++++-------
 llvm/test/tools/llvm-mc/verify/basic.s        | 35 ++++++++++++++
 mlir/docs/Diagnostics.md                      |  3 +-
 .../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/OpenMP/memory-effects.mlir  | 12 ++---
 mlir/test/Dialect/SCF/loop-pipelining.mlir    |  2 +-
 .../Transform/check-use-after-free.mlir       |  4 +-
 .../Dialect/Transform/expensive-checks.mlir   |  3 +-
 .../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 ++--
 .../transform/Ch1/invalidation-1.mlir         |  6 ++-
 mlir/test/IR/invalid-builtin-attributes.mlir  |  2 +-
 mlir/test/IR/test-verification-order.mlir     |  4 +-
 22 files changed, 111 insertions(+), 63 deletions(-)

diff --git a/clang/test/CIR/IR/invalid-vtable.cir b/clang/test/CIR/IR/invalid-vtable.cir
index f444a0ee5b539d..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 {{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/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/llvm/docs/CommandGuide/llvm-mc.md b/llvm/docs/CommandGuide/llvm-mc.md
index 2406dbed82e0eb..b4f629038f3159 100644
--- a/llvm/docs/CommandGuide/llvm-mc.md
+++ b/llvm/docs/CommandGuide/llvm-mc.md
@@ -170,7 +170,7 @@ Check diagnostics against directives in single-line comments instead of printing
 Directives have the form:
 
 ```text
-<prefix>-<kind>[-re][@<offset>][:<col>] {{<text>}}
+<prefix>-<kind>[-re][@<offset>][:<col>] [<count>] {{<text>}}
 ```
 
 - `<prefix>`: `expected` by default, or any prefix listed in the comma-separated `<prefixes>` argument.
@@ -183,6 +183,7 @@ Directives have the form:
   - `@unknown`: a diagnostic with no source location.
 - `:<col>`: the expected 1-based column.
   (Note that in Clang, `@<file>:<line>` instead refers to a line in another file.)
+- `<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 1d12fa1ea5bc85..3c5cc00b0ceb37 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
@@ -79,8 +79,10 @@ class LLVM_ABI SourceMgrDiagnosticVerifier {
     unsigned colNo = 0;
     /// 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 f38d55702d1d66..eed936022fe596 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -101,7 +101,7 @@ static Regex buildExpectedRegex(ArrayRef<StringRef> prefixes) {
       [&] { pattern += '|'; });
   pattern += ")-(error|note|remark|warning)(-re)?"
              "( *@([+-][0-9]+|above|below|unknown))?(:([0-9]+))?"
-             " *{{(.*)}}$";
+             "( +([0-9]+))? *{{(.*)}}$";
   return Regex(pattern);
 }
 
@@ -128,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, 10> matches;
+    SmallVector<StringRef, 12> matches;
     if (!expected.match(lines[lineNo].rtrim(), &matches)) {
       // Check for designators that apply to this line.
       if (!designatorsForNextLine.empty()) {
@@ -154,7 +154,7 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
       assert(matches[3] == "note");
       kind = SourceMgr::DK_Note;
     }
-    ExpectedDiag record(kind, lineNo + 1, expectedStart, matches[9]);
+    ExpectedDiag record(kind, lineNo + 1, expectedStart, matches[11]);
 
     // Check to see if this is a regex match, i.e. it includes the `-re`.
     if (!matches[4].empty() && !record.computeRegex(os, mgr)) {
@@ -169,6 +169,14 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
       continue;
     }
 
+    if (!matches[10].empty() &&
+        (matches[10].getAsInteger(10, record.numExpected) ||
+         record.numExpected == 0)) {
+      record.emitError(os, mgr, "invalid count '" + matches[10] + "'");
+      ok = false;
+      continue;
+    }
+
     StringRef offsetMatch = matches[6];
     if (!offsetMatch.empty()) {
       // Get the integer value without the @ and +/- prefix.
@@ -240,23 +248,21 @@ SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process(
   // 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 (hasLoc && e.colNo != 0 && e.colNo != colNo)
       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)
@@ -278,12 +284,18 @@ SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process(
 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 776e68da473f7d..db299dbdfa6ed6 100644
--- a/llvm/test/tools/llvm-mc/verify/basic.s
+++ b/llvm/test/tools/llvm-mc/verify/basic.s
@@ -31,6 +31,19 @@
 .quux_directive // expected-error {{unknown directive}}
 .col_directive # expected-error:1 {{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:16 {{invalid operand for instruction}}
 
@@ -105,6 +118,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 a77991e2aecb93..d90bcba6cf467e 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -318,7 +318,7 @@ 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)?(@([+-][0-9]+|above|below|unknown))?(:[0-9]+)? {{ message }}`
+*   `expected-(error|note|remark|warning)(-re)?(@([+-][0-9]+|above|below|unknown))?(:[0-9]+)?( [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
@@ -326,6 +326,7 @@ diagnostic. The `-re` suffix may be used to enable regex matching within the
 `{{` `}}` blocks. The regular expression matcher supports Extended POSIX regular
 expressions (ERE).
 An optional `:<col>` requires the diagnostic to be emitted at the given 1-based column.
+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:
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/OpenMP/memory-effects.mlir b/mlir/test/Dialect/OpenMP/memory-effects.mlir
index 00ac885c9181d4..3fe53a6349a6e0 100644
--- a/mlir/test/Dialect/OpenMP/memory-effects.mlir
+++ b/mlir/test/Dialect/OpenMP/memory-effects.mlir
@@ -174,8 +174,8 @@ func.func private @copy_ptr(!llvm.ptr, !llvm.ptr)
 func.func @single_unbounded_copyprivate_effects(%x: memref<i32>) {
   // An unannotated copy function may access arbitrary memory, allocate or free.
   // 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.single copyprivate(%x -> @copy_i32 : memref<i32>) {
@@ -201,8 +201,8 @@ func.func @single_bounded_copyprivate_effects(%x: memref<i32>, %y: !llvm.ptr) {
 func.func @single_bounded_private_unbounded_copyprivate(%x: memref<i32>, %y: memref<i32>) {
   // A bounded private clause does not constrain the copy function.
   // 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.single copyprivate(%x -> @copy_i32 : memref<i32>)
@@ -215,8 +215,8 @@ func.func @single_bounded_private_unbounded_copyprivate(%x: memref<i32>, %y: mem
 func.func @single_unbounded_private_bounded_copyprivate(%x: memref<i32>, %y: memref<i32>) {
   // A bounded copy function does not constrain the private recipe.
   // 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.single copyprivate(%x -> @copy_i32 : memref<i32>)
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..3b7cd6d72b9d65 100644
--- a/mlir/test/Dialect/Transform/expensive-checks.mlir
+++ b/mlir/test/Dialect/Transform/expensive-checks.mlir
@@ -435,7 +435,8 @@ 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
     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/Examples/transform/Ch1/invalidation-1.mlir b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
index 6f2257c360e07e..8a10b3512c38dd 100644
--- a/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
+++ b/mlir/test/Examples/transform/Ch1/invalidation-1.mlir
@@ -34,7 +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 {{payload op}}
+  // expected-note @below {{ancestor payload op}}
+  // expected-note @below {{nested payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
 
@@ -83,7 +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 {{payload op}}
+  // expected-note @below {{ancestor payload op}}
+  // expected-note @below {{nested payload op}}
   %matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
 
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) -> ()



More information about the cfe-commits mailing list