[PATCH] D98691: [FileCheck] Fix PR49531: invalid use of string var
Thomas Preud'homme via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 16 03:23:30 PDT 2021
thopre created this revision.
thopre added reviewers: jdenny, jhenderson, probinson.
Herald added a subscriber: hiraditya.
thopre requested review of this revision.
Herald added a project: LLVM.
FileCheck string substitution block parsing code only report an invalid
variable name in a string variable use if it starts with a forbidden
character. It does not report anything if there are unparsed characters
after the variable name, i.e. [[X-Y]] is parsed as [[X]] and no error is
returned. This commit fixes that.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98691
Files:
llvm/lib/FileCheck/FileCheck.cpp
llvm/test/FileCheck/simple-var-capture.txt
llvm/unittests/FileCheck/FileCheckTest.cpp
Index: llvm/unittests/FileCheck/FileCheckTest.cpp
===================================================================
--- llvm/unittests/FileCheck/FileCheckTest.cpp
+++ llvm/unittests/FileCheck/FileCheckTest.cpp
@@ -1341,6 +1341,9 @@
// Collision with numeric variable.
EXPECT_TRUE(Tester.parsePattern("[[FOO:]]"));
+ // Invalid use of string variable.
+ EXPECT_TRUE(Tester.parsePattern("[[FOO-BAR]]"));
+
// Valid use of string variable.
EXPECT_FALSE(Tester.parsePattern("[[BAR]]"));
Index: llvm/test/FileCheck/simple-var-capture.txt
===================================================================
--- llvm/test/FileCheck/simple-var-capture.txt
+++ llvm/test/FileCheck/simple-var-capture.txt
@@ -11,3 +11,15 @@
; CHECK-NEXT: op4 {{r[0-9]+}}, [[REGa]], [[REGb]]
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck --check-prefixes INVALID-VARNAME --input-file %s %s 2>&1 \
+// RUN: | FileCheck --check-prefix INVALID-VARNAME-MSG --strict-whitespace %s
+
+5
+4
+; INVALID-VARNAME: [[X:]]
+; INVALID-VARNAME-NEXT: [[Y:]]
+; INVALID-VARNAME-NEXT: [[X-Y]]
+; INVALID-VARNAME-MSG: simple-var-capture.txt:[[#@LINE-1]]:27: error: invalid name in string variable use
+; INVALID-VARNAME-MSG-NEXT: ; {{I}}NVALID-VARNAME-NEXT: {{\[\[X-Y\]\]}}
+; INVALID-VARNAME-MSG-NEXT: {{^}} ^{{$}}
Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -1082,8 +1082,15 @@
if (IsPseudo) {
MatchStr = OrigMatchStr;
IsLegacyLineExpr = IsNumBlock = true;
- } else
+ } else {
+ if (!MatchStr.empty()) {
+ SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
+ SourceMgr::DK_Error,
+ "invalid name in string variable use");
+ return true;
+ }
SubstStr = Name;
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98691.330919.patch
Type: text/x-patch
Size: 2034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210316/f6879570/attachment.bin>
More information about the llvm-commits
mailing list