[llvm] [FileCheck]: Fix diagnostic for trailing CHECK-NOT (PR #78412)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 01:01:01 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: Vinayak Dev (vinayakdsci)
<details>
<summary>Changes</summary>
Fixes #<!-- -->70221
Fix a bug in FileCheck that corrects the error message when multiple prefixes are provided
through --check-prefixes and the trailing prefix is a PREFIX-NOT.
Earlier, only the first of the provided prefixes was displayed as the erroneous prefix, while the
actual error was on the prefix that occurred at the end of the prefix list in the input file.
Now, a variable keeps track of the last NOT prefix, and that prefix is used in the error message.
---
Full diff: https://github.com/llvm/llvm-project/pull/78412.diff
2 Files Affected:
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+4-2)
- (added) llvm/test/FileCheck/check-not-custom-prefix-trailing.txt (+12)
``````````diff
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index b728c14d288aa5b..526adf3349f099f 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 000000000000000..6f9d13538304d6c
--- /dev/null
+++ b/llvm/test/FileCheck/check-not-custom-prefix-trailing.txt
@@ -0,0 +1,12 @@
+; 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
+; END
+
+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: {{^}} ^~~~~~~~~~~~{{$}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/78412
More information about the llvm-commits
mailing list