[llvm] [FileCheck] forbid filecheck check prefix definitions to end with directive name (PR #92735)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 03:44:48 PDT 2024
https://github.com/klensy updated https://github.com/llvm/llvm-project/pull/92735
>From 7616cf8adb1c71feb9ba062a7c512fb59d9494ec Mon Sep 17 00:00:00 2001
From: klensy <klensy at users.noreply.github.com>
Date: Wed, 15 May 2024 14:30:55 +0300
Subject: [PATCH 1/3] filecheck: forbid filecheck prefix definitions end with
directive name
---
llvm/lib/FileCheck/FileCheck.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 1719f8ef2b436..09446e506065f 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -2490,6 +2490,22 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
return true;
}
+static bool ValidateCheckPrefixesSuffix(StringRef Kind,
+ ArrayRef<StringRef> SuppliedPrefixes) {
+ static const char *Suffixes[] = {"-NEXT", "-SAME", "-EMPTY", "-NOT",
+ "-COUNT", "-DAG", "-LABEL"};
+ for (StringRef Prefix : SuppliedPrefixes) {
+ for (StringRef Suffix : Suffixes) {
+ if (Prefix.ends_with(Suffix)) {
+ errs() << "error: supplied " << Kind << " prefix must not end with "
+ << "directive: '" << Suffix << "', prefix: '" << Prefix << "'\n";
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
bool FileCheck::ValidateCheckPrefixes() {
StringSet<> UniquePrefixes;
// Add default prefixes to catch user-supplied duplicates of them below.
@@ -2505,6 +2521,8 @@ bool FileCheck::ValidateCheckPrefixes() {
// incorrectly indicate that they were supplied by the user.
if (!ValidatePrefixes("check", UniquePrefixes, Req.CheckPrefixes))
return false;
+ if (!ValidateCheckPrefixesSuffix("check", Req.CheckPrefixes))
+ return false;
if (!ValidatePrefixes("comment", UniquePrefixes, Req.CommentPrefixes))
return false;
return true;
>From 04475463ce3326d6e9af442a7f53dcf5f499e7a2 Mon Sep 17 00:00:00 2001
From: klensy <klensy at users.noreply.github.com>
Date: Sun, 19 May 2024 15:54:31 +0300
Subject: [PATCH 2/3] filecheck: fix self tests for "forbid check prefixes end
with directive name"
---
.../FileCheck/comment/bad-comment-prefix.txt | 10 +++++-----
llvm/test/FileCheck/numeric-expression.txt | 16 ++++++++--------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/llvm/test/FileCheck/comment/bad-comment-prefix.txt b/llvm/test/FileCheck/comment/bad-comment-prefix.txt
index 58a8873da3218..19be577618d00 100644
--- a/llvm/test/FileCheck/comment/bad-comment-prefix.txt
+++ b/llvm/test/FileCheck/comment/bad-comment-prefix.txt
@@ -3,17 +3,17 @@
# Check empty comment prefix.
RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
RUN: -comment-prefixes= | \
-RUN: FileCheck -check-prefix=PREFIX-EMPTY %s
+RUN: FileCheck -check-prefix=EMPTY-PREFIX %s
RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
RUN: -comment-prefixes=,FOO | \
-RUN: FileCheck -check-prefix=PREFIX-EMPTY %s
+RUN: FileCheck -check-prefix=EMPTY-PREFIX %s
RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
RUN: -comment-prefixes=FOO, | \
-RUN: FileCheck -check-prefix=PREFIX-EMPTY %s
+RUN: FileCheck -check-prefix=EMPTY-PREFIX %s
RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
RUN: -comment-prefixes=FOO,,BAR | \
-RUN: FileCheck -check-prefix=PREFIX-EMPTY %s
-PREFIX-EMPTY: error: supplied comment prefix must not be the empty string
+RUN: FileCheck -check-prefix=EMPTY-PREFIX %s
+EMPTY-PREFIX: error: supplied comment prefix must not be the empty string
# Check invalid characters in comment prefix.
RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
diff --git a/llvm/test/FileCheck/numeric-expression.txt b/llvm/test/FileCheck/numeric-expression.txt
index 1430484d08ebc..f23628f5fbc9a 100644
--- a/llvm/test/FileCheck/numeric-expression.txt
+++ b/llvm/test/FileCheck/numeric-expression.txt
@@ -593,16 +593,16 @@ CALL-MISSING-ARGUMENT-MSG-NEXT: {{C}}ALL-MISSING-ARGUMENT-NEXT: {{\[\[#add\(NUMV
CALL-MISSING-ARGUMENT-MSG-NEXT: {{^}} ^{{$}}
RUN: %ProtectFileCheckOutput \
-RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-WRONG-ARGUMENT-COUNT --input-file %s %s 2>&1 \
-RUN: | FileCheck --strict-whitespace --check-prefix CALL-WRONG-ARGUMENT-COUNT-MSG %s
+RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-WRONG-ARGUMENT-NUM --input-file %s %s 2>&1 \
+RUN: | FileCheck --strict-whitespace --check-prefix CALL-WRONG-ARGUMENT-NUM-MSG %s
-CALL WRONG ARGUMENT COUNT
+CALL WRONG ARGUMENT NUM
30
-CALL-WRONG-ARGUMENT-COUNT-LABEL: CALL WRONG ARGUMENT COUNT
-CALL-WRONG-ARGUMENT-COUNT-NEXT: [[#add(NUMVAR)]]
-CALL-WRONG-ARGUMENT-COUNT-MSG: numeric-expression.txt:[[#@LINE-1]]:36: error: function 'add' takes 2 arguments but 1 given
-CALL-WRONG-ARGUMENT-COUNT-MSG-NEXT: {{C}}ALL-WRONG-ARGUMENT-COUNT-NEXT: {{\[\[#add\(NUMVAR\)\]\]}}
-CALL-WRONG-ARGUMENT-COUNT-MSG-NEXT: {{^}} ^{{$}}
+CALL-WRONG-ARGUMENT-NUM-LABEL: CALL WRONG ARGUMENT NUM
+CALL-WRONG-ARGUMENT-NUM-NEXT: [[#add(NUMVAR)]]
+CALL-WRONG-ARGUMENT-NUM-MSG: numeric-expression.txt:[[#@LINE-1]]:34: error: function 'add' takes 2 arguments but 1 given
+CALL-WRONG-ARGUMENT-NUM-MSG-NEXT: {{C}}ALL-WRONG-ARGUMENT-NUM-NEXT: {{\[\[#add\(NUMVAR\)\]\]}}
+CALL-WRONG-ARGUMENT-NUM-MSG-NEXT: {{^}} ^{{$}}
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-UNDEFINED-FUNCTION --input-file %s %s 2>&1 \
>From af7c883a363d76b4a95bc39f919dda6696538363 Mon Sep 17 00:00:00 2001
From: klensy <nightouser at gmail.com>
Date: Thu, 23 May 2024 13:44:06 +0300
Subject: [PATCH 3/3] update doc
---
llvm/docs/CommandGuide/FileCheck.rst | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/docs/CommandGuide/FileCheck.rst b/llvm/docs/CommandGuide/FileCheck.rst
index 432dafa100bfd..f9e884e9c34a9 100644
--- a/llvm/docs/CommandGuide/FileCheck.rst
+++ b/llvm/docs/CommandGuide/FileCheck.rst
@@ -43,8 +43,10 @@ and from the command line.
"``:``") one or more prefixes to match. Multiple prefixes are useful for tests
which might change for different run options, but most lines remain the same.
- FileCheck does not permit duplicate prefixes, even if one is a check prefix
- and one is a comment prefix (see :option:`--comment-prefixes` below).
+ FileCheck does not permit:
+
+ * duplicate prefixes, even if one is a check prefix and one is a comment prefix (see :option:`--comment-prefixes` below).
+ * check prefixes ending with directives (i.e. ``--check-prefix=FOO-NEXT``)
.. option:: --check-prefixes prefix1,prefix2,...
More information about the llvm-commits
mailing list