aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-02-05 14:17:28 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-02-05 14:17:28 +0000
commita5e233bf798e8045771aa20af0e8b39cb60a6d73 (patch)
tree9f53ebeda85eb85d582bf514f37d7fbff5a64aea /llvm/utils/FileCheck/FileCheck.cpp
parentf929a0f81b6f75f880796b3716ab8a858a764de9 (diff)
downloadllvm-a5e233bf798e8045771aa20af0e8b39cb60a6d73.zip
llvm-a5e233bf798e8045771aa20af0e8b39cb60a6d73.tar.gz
llvm-a5e233bf798e8045771aa20af0e8b39cb60a6d73.tar.bz2
Recommit: 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: 353173
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 eb1b5dd..0d5f38a 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -50,9 +50,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),
@@ -525,8 +526,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;