[llvm] [FileCheck] forbid filecheck prefix to end with directive name (PR #92735)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 20 03:40:34 PDT 2024
https://github.com/klensy created https://github.com/llvm/llvm-project/pull/92735
Split from https://github.com/llvm/llvm-project/pull/92248
>From a056ef796ddbe3f64bad363dbc887f9fc875100b 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/2] filecheck: forbid filecheck prefix to ends with directive
name
---
llvm/lib/FileCheck/FileCheck.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 1719f8ef2b436..a584b851a9f02 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -2468,6 +2468,9 @@ FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
ArrayRef<StringRef> SuppliedPrefixes) {
+ static const char *Suffixes[] = {"-NEXT", "-SAME", "-EMPTY", "-NOT",
+ "-COUNT", "-DAG", "-LABEL"};
+
for (StringRef Prefix : SuppliedPrefixes) {
if (Prefix.empty()) {
errs() << "error: supplied " << Kind << " prefix must not be the empty "
@@ -2486,6 +2489,13 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
<< "check and comment prefixes: '" << Prefix << "'\n";
return false;
}
+ 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;
}
>From 24d10d38d2280322f78bba8400ce89b654106e9e 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/2] filecheck: fix self tests for "forbid prefixes end with
directive name"
---
.../FileCheck/comment/bad-comment-prefix.txt | 10 +++++-----
llvm/test/FileCheck/comment/suffixes.txt | 8 ++++----
llvm/test/FileCheck/numeric-expression.txt | 16 ++++++++--------
3 files changed, 17 insertions(+), 17 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/comment/suffixes.txt b/llvm/test/FileCheck/comment/suffixes.txt
index 85b05fb5778cf..88a5c4cd3bf9e 100644
--- a/llvm/test/FileCheck/comment/suffixes.txt
+++ b/llvm/test/FileCheck/comment/suffixes.txt
@@ -1,5 +1,5 @@
-# Comment prefixes plus check directive suffixes are not comment directives
-# and are treated as plain text.
+# Comment prefixes plus check directive suffixes are forbidden.
+# FIXME: currently not verified bq ValidatePrefixes missing defaulted comment prefixes?
RUN: echo foo > %t.in
RUN: echo bar >> %t.in
@@ -12,11 +12,11 @@ RUN: FileCheck -check-prefix=CHECK1 %s
CHECK1: .chk:1:18: remark: CHECK: expected string found in input
CHECK1: .chk:2:17: remark: CHECK: expected string found in input
-# But we can define them as comment prefixes.
+# But we can define them as comment prefixes; still forbidden.
RUN: %ProtectFileCheckOutput \
RUN: FileCheck -dump-input=never -vv -comment-prefixes=COM,RUN,RUN-NOT %t.chk < %t.in 2>&1 | \
RUN: FileCheck -check-prefix=CHECK2 %s
-CHECK2: .chk:1:18: remark: CHECK: expected string found in input
+CHECK2: error: supplied comment prefix must not end with directive: '-NOT', prefix: 'RUN-NOT'
CHECK2-NOT: .chk:2
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 \
More information about the llvm-commits
mailing list