[llvm] [FileCheck]: Fix diagnostic for trailing CHECK-NOT (PR #78412)

Vinayak Dev via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 02:26:47 PST 2024


https://github.com/vinayakdsci updated https://github.com/llvm/llvm-project/pull/78412

>From c9a5dc4eba1476dfe419910b5e276d90c7b03296 Mon Sep 17 00:00:00 2001
From: Vinayak Dev <vinayakdev.sci at gmail.com>
Date: Mon, 15 Jan 2024 22:40:44 +0530
Subject: [PATCH] [FileCheck]: Fix diagnostic for trailing CHECK-NOT

---
 llvm/lib/FileCheck/FileCheck.cpp                      |  6 ++++--
 .../FileCheck/check-not-custom-prefix-trailing.txt    | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/FileCheck/check-not-custom-prefix-trailing.txt

diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index b728c14d288aa5..526adf3349f099 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1814,6 +1814,7 @@ bool FileCheck::readCheckFile(
   }
 
   std::vector<Pattern> DagNotMatches = ImplicitNegativeChecks;
+  StringRef TrailingNotPrefix;
 
   // LineNumber keeps track of the line on which CheckPrefix instances are
   // found.
@@ -1927,6 +1928,7 @@ bool FileCheck::readCheckFile(
     // Handle CHECK-DAG/-NOT.
     if (CheckTy == Check::CheckDAG || CheckTy == Check::CheckNot) {
       DagNotMatches.push_back(P);
+      TrailingNotPrefix = UsedPrefix;
       continue;
     }
 
@@ -1957,11 +1959,11 @@ bool FileCheck::readCheckFile(
   }
 
   // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
-  // and use the first prefix as a filler for the error message.
+  // and use the prefix from the last/trailing CHECK-NOT for the error message
   if (!DagNotMatches.empty()) {
     CheckStrings->emplace_back(
         Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
-        *Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
+        TrailingNotPrefix, SMLoc::getFromPointer(Buffer.data()));
     std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
   }
 
diff --git a/llvm/test/FileCheck/check-not-custom-prefix-trailing.txt b/llvm/test/FileCheck/check-not-custom-prefix-trailing.txt
new file mode 100644
index 00000000000000..22dce89fab8bd6
--- /dev/null
+++ b/llvm/test/FileCheck/check-not-custom-prefix-trailing.txt
@@ -0,0 +1,11 @@
+; RUN: rm %t && \
+; RUN: echo "LEADING: placeholder1" >>%t && echo "TRAILING-NOT: placeholder2" >>%t && \
+; RUN: %ProtectFileCheckOutput not FileCheck --strict-whitespace --check-prefixes LEADING,TRAILING --input-file %t %t 2>&1 | \ 
+; RUN: FileCheck %s
+
+CHECK:           error: TRAILING-NOT: excluded string found in input
+CHECK-NEXT:      TRAILING-NOT: placeholder2
+CHECK-NEXT: {{^}}              ^{{$}}
+CHECK-NEXT:      note: found here
+CHECK-NEXT:      TRAILING-NOT: placeholder2
+CHECK-NEXT: {{^}}              ^~~~~~~~~~~~{{$}}



More information about the llvm-commits mailing list