[llvm-branch-commits] [llvm] [mlir] [Support][mlir] Highlight the whole directive in verifier errors (PR #233309)

Alexander Richardson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 6 16:03:44 PST 2026


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

>From a9054ea7aadd73def494cdaf4f9de6a25aa1a981 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Mon, 2 Nov 2026 22:11:02 -0800
Subject: [PATCH] [nspr] initial commit

---
 llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp | 4 ++--
 llvm/test/tools/llvm-mc/verify/highlight.s       | 5 ++---
 mlir/docs/Diagnostics.md                         | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
index fc0520149a97ae..7c00be4f89c6c2 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -39,8 +39,8 @@ SourceMgrDiagnosticVerifier::getDiagKindStr(SourceMgr::DiagKind kind) {
 bool SourceMgrDiagnosticVerifier::ExpectedDiag::emitError(
     raw_ostream &os, SourceMgr &mgr, const Twine &msg) const {
   if (fileLoc.isValid()) {
-    SMRange range(fileLoc, SMLoc::getFromPointer(fileLoc.getPointer() +
-                                                 substring.size()));
+    // Highlight the whole directive, up to and including the closing '}}'.
+    SMRange range(fileLoc, SMLoc::getFromPointer(substring.end() + 2));
     printMessage(os, mgr, fileLoc, msg, range);
   } else {
     printMessage(os, mgr, fileLoc, msg);
diff --git a/llvm/test/tools/llvm-mc/verify/highlight.s b/llvm/test/tools/llvm-mc/verify/highlight.s
index 69b8784925a762..f7663ad8f23bb8 100644
--- a/llvm/test/tools/llvm-mc/verify/highlight.s
+++ b/llvm/test/tools/llvm-mc/verify/highlight.s
@@ -1,14 +1,13 @@
-## Verifier errors highlight the directive.
+## Verifier errors highlight the whole directive, up to and including '}}'.
 
 # REQUIRES: x86-registered-target
 # RUN: rm -rf %t && split-file %s %t && cd %t
 # RUN: not llvm-mc --triple=x86_64 --verify input.s 2>&1 \
 # RUN:   | FileCheck %s --strict-whitespace
 
-## FIXME: The highlight ends in the middle of the directive.
 # CHECK:      input.s:1:7: error: expected error "never produced" was not produced
 # CHECK-NEXT: {{^}}nop # expected-error {{[{][{]}}never produced{{[}][}]}}{{$}}
-# CHECK-NEXT: {{^}}      ^~~~~~~~~~~~~~{{$}}
+# CHECK-NEXT: {{^}}      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{{$}}
 
 #--- input.s
 nop # expected-error {{never produced}}
diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md
index d90bcba6cf467e..ad0cb37467b621 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -374,7 +374,7 @@ func.func @foo() -> (index, ind) {
 
 /tmp/test.mlir:15:4: error: expected remark "expected some remark" was not produced
 // expected-remark {{expected some remark}}
-   ^~~~~~~~~~~~~~~~~~~~~~~~~~
+   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ```
 
 Similarly to the [SourceMgr Diagnostic Handler](#sourcemgr-diagnostic-handler),



More information about the llvm-branch-commits mailing list