[llvm] 058455f - [FileCheck] Fix PR49531: invalid use of string var
Thomas Preud'homme via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 24 11:49:58 PDT 2021
Author: Thomas Preud'homme
Date: 2021-03-24T18:49:58Z
New Revision: 058455ffbec13bd1bc468a0206b9e3a95dc4b8c8
URL: https://github.com/llvm/llvm-project/commit/058455ffbec13bd1bc468a0206b9e3a95dc4b8c8
DIFF: https://github.com/llvm/llvm-project/commit/058455ffbec13bd1bc468a0206b9e3a95dc4b8c8.diff
LOG: [FileCheck] Fix PR49531: invalid use of string var
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.
Reviewed By: jdenny, jhenderson
Differential Revision: https://reviews.llvm.org/D98691
Added:
Modified:
llvm/lib/FileCheck/FileCheck.cpp
llvm/test/FileCheck/simple-var-capture.txt
llvm/unittests/FileCheck/FileCheckTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index bcf828d20ee8..12a0ae63419f 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1083,8 +1083,15 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix,
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;
+ }
}
}
diff --git a/llvm/test/FileCheck/simple-var-capture.txt b/llvm/test/FileCheck/simple-var-capture.txt
index a487baaa531c..d9f456130e02 100644
--- a/llvm/test/FileCheck/simple-var-capture.txt
+++ b/llvm/test/FileCheck/simple-var-capture.txt
@@ -11,3 +11,15 @@ op4 r30, r18, r21
; 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: {{^}} ^{{$}}
diff --git a/llvm/unittests/FileCheck/FileCheckTest.cpp b/llvm/unittests/FileCheck/FileCheckTest.cpp
index 299fbb8a7985..f54b940d68c4 100644
--- a/llvm/unittests/FileCheck/FileCheckTest.cpp
+++ b/llvm/unittests/FileCheck/FileCheckTest.cpp
@@ -1343,6 +1343,9 @@ TEST_F(FileCheckTest, ParsePattern) {
// 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]]"));
More information about the llvm-commits
mailing list