diff options
Diffstat (limited to 'llvm/docs/CommandGuide/FileCheck.rst')
-rw-r--r-- | llvm/docs/CommandGuide/FileCheck.rst | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/llvm/docs/CommandGuide/FileCheck.rst b/llvm/docs/CommandGuide/FileCheck.rst index bc216be35df..e54ab762cd2 100644 --- a/llvm/docs/CommandGuide/FileCheck.rst +++ b/llvm/docs/CommandGuide/FileCheck.rst @@ -499,8 +499,8 @@ simply uniquely match a single line in the file being verified. ``CHECK-LABEL:`` directives cannot contain variable definitions or uses. -FileCheck Pattern Matching Syntax -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FileCheck Regex Matching Syntax +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All FileCheck directives take a pattern to match. For most uses of FileCheck, fixed string matching is perfectly sufficient. For @@ -525,14 +525,15 @@ braces like you would in C. In the rare case that you want to match double braces explicitly from the input, you can use something ugly like ``{{[{][{]}}`` as your pattern. -FileCheck Pattern Expressions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FileCheck String Substitution Blocks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It is often useful to match a pattern and then verify that it occurs again -later in the file. For codegen tests, this can be useful to allow any register, -but verify that that register is used consistently later. To do this, -:program:`FileCheck` supports pattern expressions that allow pattern variables -to be defined and substituted into patterns. Here is a simple example: +later in the file. For codegen tests, this can be useful to allow any +register, but verify that that register is used consistently later. To do +this, :program:`FileCheck` supports string substitution blocks that allow +string variables to be defined and substituted into patterns. Here is a simple +example: .. code-block:: llvm @@ -541,15 +542,16 @@ to be defined and substituted into patterns. Here is a simple example: ; CHECK: andw {{.*}}[[REGISTER]] The first check line matches a regex ``%[a-z]+`` and captures it into the -variable ``REGISTER``. The second line verifies that whatever is in -``REGISTER`` occurs later in the file after an "``andw``". :program:`FileCheck` -variable references are always contained in ``[[ ]]`` pairs, and their names can -be formed with the regex ``[a-zA-Z_][a-zA-Z0-9_]*``. If a colon follows the name, -then it is a definition of the variable; otherwise, it is a use. +string variable ``REGISTER``. The second line verifies that whatever is in +``REGISTER`` occurs later in the file after an "``andw``". :program:`FileCheck` +string substitution blocks are always contained in ``[[ ]]`` pairs, and string +variable names can be formed with the regex ``[a-zA-Z_][a-zA-Z0-9_]*``. If a +colon follows the name, then it is a definition of the variable; otherwise, it +is a substitution. -:program:`FileCheck` variables can be defined multiple times, and uses always -get the latest value. Variables can also be used later on the same line they -were defined on. For example: +:program:`FileCheck` variables can be defined multiple times, and substitutions +always get the latest value. Variables can also be substituted later on the +same line they were defined on. For example: .. code-block:: llvm @@ -565,16 +567,17 @@ CHECK-LABEL block. Global variables are not affected by CHECK-LABEL. This makes it easier to ensure that individual tests are not affected by variables set in preceding tests. -FileCheck Numeric Variables and Expressions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FileCheck Numeric Substitution Blocks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:program:`FileCheck` also allows checking for numeric values that satisfy a -numeric expression constraint based on numeric variables. This allows -``CHECK:`` directives to verify a numeric relation between two numbers, such as -the need for consecutive registers to be used. +:program:`FileCheck` also supports numeric substitution blocks that allow +checking for numeric values that satisfy a numeric expression constraint based +on numeric variables. This allows ``CHECK:`` directives to verify a numeric +relation between two numbers, such as the need for consecutive registers to be +used. -The syntax to check a numeric expression constraint is -``[[#<NUMVAR><op><offset>]]`` where: +The syntax of a numeric substitution block is ``[[#<NUMVAR><op><offset>]]`` +where: * ``<NUMVAR>`` is the name of a numeric variable defined on the command line. @@ -585,6 +588,10 @@ The syntax to check a numeric expression constraint is the numeric operation <op>. It must be present if ``<op>`` is present, absent otherwise. +Spaces are accepted before, after and between any of these elements. + +Unlike string substitution blocks, numeric substitution blocks only introduce +numeric substitutions which substitute a numeric expression for its value. For example: .. code-block:: llvm @@ -606,7 +613,7 @@ but would not match the line: due to ``7`` being unequal to ``5 + 1``. The ``--enable-var-scope`` option has the same effect on numeric variables as -on pattern variables. +on string variables. FileCheck Pseudo Numeric Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -632,9 +639,9 @@ relative line number references, for example: // CHECK-NEXT: {{^ ;}} int a -To support legacy uses of ``@LINE`` as a special pattern variable, -:program:`FileCheck` also accepts the following uses of ``@LINE`` with pattern -variable syntax: ``[[@LINE]]``, ``[[@LINE+<offset>]]`` and +To support legacy uses of ``@LINE`` as a special string variable, +:program:`FileCheck` also accepts the following uses of ``@LINE`` with string +substitution block syntax: ``[[@LINE]]``, ``[[@LINE+<offset>]]`` and ``[[@LINE-<offset>]]`` without any spaces inside the brackets and where ``offset`` is an integer. |