https://github.com/arichardson created https://github.com/llvm/llvm-project/pull/233309
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 >From bc7555321635a560bc378f160717e41a8896ba59 Mon Sep 17 00:00:00 2001 From: Alex Richardson <[email protected]> Date: Sun, 18 Oct 2026 15:09:11 -0700 Subject: [PATCH] [nspr] initial commit --- llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp | 4 ++-- .../Support/SourceMgrDiagnosticVerifierTest.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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; +} _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
