aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-01-14 09:29:10 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-01-14 09:29:10 +0000
commit84f4ff5119e5c29ec68093e791c926f98ea60c9c (patch)
treec24e8178fe73051726e6796f1f4f0d93ca3f73bc /llvm/utils/FileCheck/FileCheck.cpp
parentbc5e6ee87a08618c3202eb1cecddd24267e64701 (diff)
downloadllvm-84f4ff5119e5c29ec68093e791c926f98ea60c9c.zip
llvm-84f4ff5119e5c29ec68093e791c926f98ea60c9c.tar.gz
llvm-84f4ff5119e5c29ec68093e791c926f98ea60c9c.tar.bz2
Detect incorrect FileCheck variable CLI definition
Summary: While the backend code of FileCheck relies on definition of variable from the command-line to have an equal sign '=' and a variable name before that, the frontend does not actually enforce it. This leads to FileCheck crashing when invoked with invalid syntax for the -D option. This patch adds the missing validation in the frontend. It also makes the -D option an AlwaysPrefix option to be able to detect -D=FOO as being a define without variable and -D as missing its value. Copyright: - Linaro (changes in version 2 of revision D55940) - GraphCore (changes in later versions) Reviewers: jdenny Subscribers: JonChesterfield, hiraditya, kristina, probinson, llvm-commits Differential Revision: https://reviews.llvm.org/D55940 llvm-svn: 351039
Diffstat (limited to 'llvm/utils/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/utils/FileCheck/FileCheck.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index fdfd3e7..39245d2 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -51,9 +51,10 @@ static cl::list<std::string> ImplicitCheckNot(
"this pattern occur which are not matched by a positive pattern"),
cl::value_desc("pattern"));
-static cl::list<std::string> GlobalDefines("D", cl::Prefix,
- cl::desc("Define a variable to be used in capture patterns."),
- cl::value_desc("VAR=VALUE"));
+static cl::list<std::string>
+ GlobalDefines("D", cl::AlwaysPrefix,
+ cl::desc("Define a variable to be used in capture patterns."),
+ cl::value_desc("VAR=VALUE"));
static cl::opt<bool> AllowEmptyInput(
"allow-empty", cl::init(false),
@@ -523,8 +524,25 @@ int main(int argc, char **argv) {
for (auto CheckNot : ImplicitCheckNot)
Req.ImplicitCheckNot.push_back(CheckNot);
- for (auto G : GlobalDefines)
+ bool GlobalDefineError = false;
+ for (auto G : GlobalDefines) {
+ size_t EqIdx = G.find('=');
+ if (EqIdx == std::string::npos) {
+ errs() << "Missing equal sign in command-line definition '-D" << G
+ << "'\n";
+ GlobalDefineError = true;
+ continue;
+ }
+ if (EqIdx == 0) {
+ errs() << "Missing pattern variable name in command-line definition '-D"
+ << G << "'\n";
+ GlobalDefineError = true;
+ continue;
+ }
Req.GlobalDefines.push_back(G);
+ }
+ if (GlobalDefineError)
+ return 2;
Req.AllowEmptyInput = AllowEmptyInput;
Req.EnableVarScope = EnableVarScope;