llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Alexander Richardson (arichardson)

<details>
<summary>Changes</summary>

The highlighted range started at the directive but had the length of the
expected text, so it usually ended in the middle of the directive.
Highlight up to and including the closing `}}` instead.

Assisted-by: AI tooling

---
Full diff: https://github.com/llvm/llvm-project/pull/233309.diff


2 Files Affected:

- (modified) llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp (+2-2) 
- (modified) llvm/unittests/Support/SourceMgrDiagnosticVerifierTest.cpp (+11) 


``````````diff
diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp 
b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
index 9e567d5e49f51..5ef9b59976930 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -68,9 +68,9 @@ bool SourceMgrDiagnosticVerifier::emitError(const 
ExpectedDiag &Diag,
   SMRange Range;
   ArrayRef<SMRange> Ranges;
   if (Diag.FileLoc.isValid()) {
+    // Highlight the whole directive, up to and including the closing '}}'.
     Range =
-        SMRange(Diag.FileLoc, SMLoc::getFromPointer(Diag.FileLoc.getPointer() +
-                                                    Diag.Substring.size()));
+        SMRange(Diag.FileLoc, SMLoc::getFromPointer(Diag.Substring.end() + 2));
     Ranges = Range;
   }
   printDiag(Mgr.GetMessage(Diag.FileLoc, SourceMgr::DK_Error, Msg, Ranges));
diff --git a/llvm/unittests/Support/SourceMgrDiagnosticVerifierTest.cpp 
b/llvm/unittests/Support/SourceMgrDiagnosticVerifierTest.cpp
index 6bbd12e720c80..16954bed53515 100644
--- a/llvm/unittests/Support/SourceMgrDiagnosticVerifierTest.cpp
+++ b/llvm/unittests/Support/SourceMgrDiagnosticVerifierTest.cpp
@@ -262,3 +262,14 @@ TEST_F(SourceMgrDiagnosticVerifierTest, 
AlreadyMatchedIsNotNearMiss) {
   EXPECT_EQ(StringRef(Output).find("diagnostic emitted when expecting"),
             StringRef::npos);
 }
+
+TEST_F(SourceMgrDiagnosticVerifierTest, ErrorHighlightsWholeDirective) {
+  addBuffer("op\n# expected-error@-1 {{missing}}\n");
+  SourceMgrDiagnosticVerifier Verifier(SM, OS);
+
+  EXPECT_FALSE(Verifier.verify());
+  EXPECT_NE(StringRef(Output).find("# expected-error@-1 {{missing}}\n"
+                                   "  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"),
+            StringRef::npos)
+      << Output;
+}

``````````

</details>


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

Reply via email to