llvm.org GIT mirror llvm / fe0523d
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351039 91177308-0d34-0410-b5e6-96231b3b80d8 Thomas Preud'homme 10 months ago
2 changed file(s) with 43 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
22 ;
33 ; RUN: not FileCheck -DVALUE=10 -check-prefix NOT -input-file %s %s 2>&1 | FileCheck %s -check-prefix NOT-ERRMSG
44 ; RUN: FileCheck -DVALUE=20 -check-prefix NOT -input-file %s %s
5 ; RUN: not FileCheck -DVALUE10 -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRCLIEQ1
6 ; RUN: not FileCheck -D -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRCLIEQ2
7 ; RUN: not FileCheck -D=10 -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRCLIVAR1
8 ; RUN: not FileCheck -D= -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRCLIVAR2
9 ; RUN: FileCheck -DVALUE= -check-prefix EMPTY -input-file %s %s 2>&1
510
611 Value = 10
712 ; CHECK: Value = [[VALUE]]
813 ; NOT-NOT: Value = [[VALUE]]
914
10 ; ERRMSG: defines.txt:8:10: error: CHECK: expected string not found in input
15 ; ERRMSG: defines.txt:[[@LINE-3]]:10: error: CHECK: expected string not found in input
1116 ; ERRMSG: defines.txt:1:1: note: scanning from here
1217 ; ERRMSG: defines.txt:1:1: note: with variable "VALUE" equal to "20"
13 ; ERRMSG: defines.txt:7:1: note: possible intended match here
18 ; ERRMSG: defines.txt:[[@LINE-7]]:1: note: possible intended match here
1419
15 ; NOT-ERRMSG: defines.txt:9:12: error: {{NOT}}-NOT: excluded string found in input
16 ; NOT-ERRMSG: defines.txt:7:1: note: found here
17 ; NOT-ERRMSG: defines.txt:7:1: note: with variable "VALUE" equal to "10"
20 ; NOT-ERRMSG: defines.txt:[[@LINE-7]]:12: error: {{NOT}}-NOT: excluded string found in input
21 ; NOT-ERRMSG: defines.txt:[[@LINE-10]]:1: note: found here
22 ; NOT-ERRMSG: defines.txt:[[@LINE-11]]:1: note: with variable "VALUE" equal to "10"
23
24 ; ERRCLIEQ1: Missing equal sign in command-line definition '-DVALUE10'
25
26 ; ERRCLIEQ2: FileCheck: for the -D option: requires a value!
27
28 ; ERRCLIVAR1: Missing pattern variable name in command-line definition '-D=10'
29
30 ; ERRCLIVAR2: Missing pattern variable name in command-line definition '-D='
31
32 Empty value = @@
33 ; EMPTY: Empty value = @[[VALUE]]@
5050 "this pattern occur which are not matched by a positive pattern"),
5151 cl::value_desc("pattern"));
5252
53 static cl::list GlobalDefines("D", cl::Prefix,
54 cl::desc("Define a variable to be used in capture patterns."),
55 cl::value_desc("VAR=VALUE"));
53 static cl::list
54 GlobalDefines("D", cl::AlwaysPrefix,
55 cl::desc("Define a variable to be used in capture patterns."),
56 cl::value_desc("VAR=VALUE"));
5657
5758 static cl::opt AllowEmptyInput(
5859 "allow-empty", cl::init(false),
522523 for (auto CheckNot : ImplicitCheckNot)
523524 Req.ImplicitCheckNot.push_back(CheckNot);
524525
525 for (auto G : GlobalDefines)
526 bool GlobalDefineError = false;
527 for (auto G : GlobalDefines) {
528 size_t EqIdx = G.find('=');
529 if (EqIdx == std::string::npos) {
530 errs() << "Missing equal sign in command-line definition '-D" << G
531 << "'\n";
532 GlobalDefineError = true;
533 continue;
534 }
535 if (EqIdx == 0) {
536 errs() << "Missing pattern variable name in command-line definition '-D"
537 << G << "'\n";
538 GlobalDefineError = true;
539 continue;
540 }
526541 Req.GlobalDefines.push_back(G);
542 }
543 if (GlobalDefineError)
544 return 2;
527545
528546 Req.AllowEmptyInput = AllowEmptyInput;
529547 Req.EnableVarScope = EnableVarScope;