[PATCH] D39629: Add a -D flag to FileCheck to define variables

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 05:25:30 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL317572: Add a -D flag to FileCheck to define variables (authored by arichardson).

Changed prior to commit:
  https://reviews.llvm.org/D39629?vs=121590&id=121876#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39629

Files:
  llvm/trunk/docs/CommandGuide/FileCheck.rst
  llvm/trunk/test/FileCheck/defines.txt
  llvm/trunk/utils/FileCheck/FileCheck.cpp


Index: llvm/trunk/test/FileCheck/defines.txt
===================================================================
--- llvm/trunk/test/FileCheck/defines.txt
+++ llvm/trunk/test/FileCheck/defines.txt
@@ -0,0 +1,9 @@
+; RUN: FileCheck -DVALUE=10 -input-file %s %s
+; RUN: not FileCheck -DVALUE=20 -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRMSG
+
+Value = 10
+; CHECK: Value = [[VALUE]]
+
+; ERRMSG: defines.txt:5:10: error: expected string not found in input
+; ERRMSG: defines.txt:1:1: note: with variable "VALUE" equal to "20"
+; ERRMSG: defines.txt:4:1: note: possible intended match here
Index: llvm/trunk/utils/FileCheck/FileCheck.cpp
===================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp
@@ -62,6 +62,10 @@
              "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::opt<bool> AllowEmptyInput(
     "allow-empty", cl::init(false),
     cl::desc("Allow the input file to be empty. This is useful when making\n"
@@ -1295,6 +1299,9 @@
   /// VariableTable - This holds all the current filecheck variables.
   StringMap<StringRef> VariableTable;
 
+  for (const auto& Def : GlobalDefines)
+    VariableTable.insert(StringRef(Def).split('='));
+
   unsigned i = 0, j = 0, e = CheckStrings.size();
   while (true) {
     StringRef CheckRegion;
Index: llvm/trunk/docs/CommandGuide/FileCheck.rst
===================================================================
--- llvm/trunk/docs/CommandGuide/FileCheck.rst
+++ llvm/trunk/docs/CommandGuide/FileCheck.rst
@@ -86,6 +86,11 @@
 
   All other variables get undefined after each encountered ``CHECK-LABEL``.
 
+.. option:: -D<VAR=VALUE>
+
+  Sets a filecheck variable ``VAR`` with value ``VALUE`` that can be used in
+  ``CHECK:`` lines.
+
 .. option:: -version
 
  Show the version number of this program.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39629.121876.patch
Type: text/x-patch
Size: 2099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171107/528aec68/attachment.bin>


More information about the llvm-commits mailing list