Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 1 | FileCheck - Flexible pattern matching file verifier |
| 2 | =================================================== |
| 3 | |
James Henderson | a056684 | 2019-06-27 13:24:46 +0000 | [diff] [blame] | 4 | .. program:: FileCheck |
| 5 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 6 | SYNOPSIS |
| 7 | -------- |
| 8 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 9 | :program:`FileCheck` *match-filename* [*--check-prefix=XXX*] [*--strict-whitespace*] |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 10 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 11 | DESCRIPTION |
| 12 | ----------- |
| 13 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 14 | :program:`FileCheck` reads two files (one from standard input, and one |
| 15 | specified on the command line) and uses one to verify the other. This |
| 16 | behavior is particularly useful for the testsuite, which wants to verify that |
| 17 | the output of some tool (e.g. :program:`llc`) contains the expected information |
| 18 | (for example, a movsd from esp or whatever is interesting). This is similar to |
| 19 | using :program:`grep`, but it is optimized for matching multiple different |
| 20 | inputs in one file in a specific order. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 21 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 22 | The ``match-filename`` file specifies the file that contains the patterns to |
Stephen Lin | a6e877f | 2013-07-14 18:12:25 +0000 | [diff] [blame] | 23 | match. The file to verify is read from standard input unless the |
| 24 | :option:`--input-file` option is used. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 25 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 26 | OPTIONS |
| 27 | ------- |
| 28 | |
Joel E. Denny | 24994d7 | 2018-11-06 22:07:03 +0000 | [diff] [blame] | 29 | Options are parsed from the environment variable ``FILECHECK_OPTS`` |
| 30 | and from the command line. |
| 31 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 32 | .. option:: -help |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 33 | |
| 34 | Print a summary of command line options. |
| 35 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 36 | .. option:: --check-prefix prefix |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 37 | |
Matt Arsenault | 13df462 | 2013-11-10 02:04:09 +0000 | [diff] [blame] | 38 | FileCheck searches the contents of ``match-filename`` for patterns to |
| 39 | match. By default, these patterns are prefixed with "``CHECK:``". |
| 40 | If you'd like to use a different prefix (e.g. because the same input |
| 41 | file is checking multiple different tool or options), the |
| 42 | :option:`--check-prefix` argument allows you to specify one or more |
| 43 | prefixes to match. Multiple prefixes are useful for tests which might |
| 44 | change for different run options, but most lines remain the same. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 45 | |
Daniel Sanders | ad875c2 | 2016-06-14 16:42:05 +0000 | [diff] [blame] | 46 | .. option:: --check-prefixes prefix1,prefix2,... |
| 47 | |
| 48 | An alias of :option:`--check-prefix` that allows multiple prefixes to be |
| 49 | specified as a comma separated list. |
| 50 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 51 | .. option:: --input-file filename |
Eli Bendersky | 8a7e80f | 2012-11-07 01:41:30 +0000 | [diff] [blame] | 52 | |
| 53 | File to check (defaults to stdin). |
| 54 | |
James Y Knight | 85913cc | 2016-02-11 16:46:09 +0000 | [diff] [blame] | 55 | .. option:: --match-full-lines |
| 56 | |
| 57 | By default, FileCheck allows matches of anywhere on a line. This |
| 58 | option will require all positive matches to cover an entire |
| 59 | line. Leading and trailing whitespace is ignored, unless |
| 60 | :option:`--strict-whitespace` is also specified. (Note: negative |
| 61 | matches from ``CHECK-NOT`` are not affected by this option!) |
| 62 | |
| 63 | Passing this option is equivalent to inserting ``{{^ *}}`` or |
| 64 | ``{{^}}`` before, and ``{{ *$}}`` or ``{{$}}`` after every positive |
| 65 | check pattern. |
| 66 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 67 | .. option:: --strict-whitespace |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 68 | |
| 69 | By default, FileCheck canonicalizes input horizontal whitespace (spaces and |
| 70 | tabs) which causes it to ignore these differences (a space will match a tab). |
Guy Benyei | 5ea04c3 | 2013-02-06 20:40:38 +0000 | [diff] [blame] | 71 | The :option:`--strict-whitespace` argument disables this behavior. End-of-line |
Sean Silva | b6bfbad | 2013-06-21 00:27:54 +0000 | [diff] [blame] | 72 | sequences are canonicalized to UNIX-style ``\n`` in all modes. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 73 | |
Alexander Kornienko | 56ccdbb | 2014-07-11 12:39:32 +0000 | [diff] [blame] | 74 | .. option:: --implicit-check-not check-pattern |
| 75 | |
| 76 | Adds implicit negative checks for the specified patterns between positive |
| 77 | checks. The option allows writing stricter tests without stuffing them with |
Dan Liew | a762a13 | 2014-07-21 16:39:00 +0000 | [diff] [blame] | 78 | ``CHECK-NOT``\ s. |
Alexander Kornienko | 56ccdbb | 2014-07-11 12:39:32 +0000 | [diff] [blame] | 79 | |
| 80 | For example, "``--implicit-check-not warning:``" can be useful when testing |
| 81 | diagnostic messages from tools that don't have an option similar to ``clang |
| 82 | -verify``. With this option FileCheck will verify that input does not contain |
| 83 | warnings not covered by any ``CHECK:`` patterns. |
| 84 | |
Joel E. Denny | 3c5d267 | 2018-12-18 00:01:39 +0000 | [diff] [blame] | 85 | .. option:: --dump-input <mode> |
| 86 | |
| 87 | Dump input to stderr, adding annotations representing currently enabled |
| 88 | diagnostics. Do this either 'always', on 'fail', or 'never'. Specify 'help' |
| 89 | to explain the dump format and quit. |
| 90 | |
George Karpenkov | 346dfbe | 2018-07-20 20:21:57 +0000 | [diff] [blame] | 91 | .. option:: --dump-input-on-failure |
| 92 | |
Joel E. Denny | 3c5d267 | 2018-12-18 00:01:39 +0000 | [diff] [blame] | 93 | When the check fails, dump all of the original input. This option is |
| 94 | deprecated in favor of `--dump-input=fail`. |
George Karpenkov | 346dfbe | 2018-07-20 20:21:57 +0000 | [diff] [blame] | 95 | |
Artem Belevich | f55e72a | 2017-03-09 17:59:04 +0000 | [diff] [blame] | 96 | .. option:: --enable-var-scope |
| 97 | |
| 98 | Enables scope for regex variables. |
| 99 | |
| 100 | Variables with names that start with ``$`` are considered global and |
| 101 | remain set throughout the file. |
| 102 | |
| 103 | All other variables get undefined after each encountered ``CHECK-LABEL``. |
| 104 | |
Alexander Richardson | 46e1fd6 | 2017-11-07 13:24:44 +0000 | [diff] [blame] | 105 | .. option:: -D<VAR=VALUE> |
| 106 | |
Thomas Preud'homme | 288ed91 | 2019-05-02 00:04:38 +0000 | [diff] [blame] | 107 | Sets a filecheck pattern variable ``VAR`` with value ``VALUE`` that can be |
| 108 | used in ``CHECK:`` lines. |
Alexander Richardson | 46e1fd6 | 2017-11-07 13:24:44 +0000 | [diff] [blame] | 109 | |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 110 | .. option:: -D#<NUMVAR>=<VALUE> |
| 111 | |
| 112 | Sets a filecheck numeric variable ``NUMVAR`` to ``<VALUE>`` that can be used |
| 113 | in ``CHECK:`` lines. |
| 114 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 115 | .. option:: -version |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 116 | |
| 117 | Show the version number of this program. |
| 118 | |
Joel E. Denny | dc5ba31 | 2018-07-13 03:08:23 +0000 | [diff] [blame] | 119 | .. option:: -v |
| 120 | |
Joel E. Denny | 352695c | 2019-01-22 21:41:42 +0000 | [diff] [blame] | 121 | Print good directive pattern matches. However, if ``-input-dump=fail`` or |
| 122 | ``-input-dump=always``, add those matches as input annotations instead. |
Joel E. Denny | dc5ba31 | 2018-07-13 03:08:23 +0000 | [diff] [blame] | 123 | |
| 124 | .. option:: -vv |
| 125 | |
| 126 | Print information helpful in diagnosing internal FileCheck issues, such as |
| 127 | discarded overlapping ``CHECK-DAG:`` matches, implicit EOF pattern matches, |
| 128 | and ``CHECK-NOT:`` patterns that do not have matches. Implies ``-v``. |
Joel E. Denny | 352695c | 2019-01-22 21:41:42 +0000 | [diff] [blame] | 129 | However, if ``-input-dump=fail`` or ``-input-dump=always``, just add that |
| 130 | information as input annotations instead. |
Joel E. Denny | dc5ba31 | 2018-07-13 03:08:23 +0000 | [diff] [blame] | 131 | |
Joel E. Denny | bcf5b44 | 2018-07-11 20:27:27 +0000 | [diff] [blame] | 132 | .. option:: --allow-deprecated-dag-overlap |
| 133 | |
| 134 | Enable overlapping among matches in a group of consecutive ``CHECK-DAG:`` |
| 135 | directives. This option is deprecated and is only provided for convenience |
| 136 | as old tests are migrated to the new non-overlapping ``CHECK-DAG:`` |
| 137 | implementation. |
| 138 | |
Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 139 | .. option:: --color |
| 140 | |
| 141 | Use colors in output (autodetected by default). |
| 142 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 143 | EXIT STATUS |
| 144 | ----------- |
| 145 | |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 146 | If :program:`FileCheck` verifies that the file matches the expected contents, |
| 147 | it exits with 0. Otherwise, if not, or if an error occurs, it will exit with a |
| 148 | non-zero value. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 149 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 150 | TUTORIAL |
| 151 | -------- |
| 152 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 153 | FileCheck is typically used from LLVM regression tests, being invoked on the RUN |
| 154 | line of the test. A simple example of using FileCheck from a RUN line looks |
| 155 | like this: |
| 156 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 157 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 158 | |
| 159 | ; RUN: llvm-as < %s | llc -march=x86-64 | FileCheck %s |
| 160 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 161 | This syntax says to pipe the current file ("``%s``") into ``llvm-as``, pipe |
| 162 | that into ``llc``, then pipe the output of ``llc`` into ``FileCheck``. This |
| 163 | means that FileCheck will be verifying its standard input (the llc output) |
| 164 | against the filename argument specified (the original ``.ll`` file specified by |
| 165 | "``%s``"). To see how this works, let's look at the rest of the ``.ll`` file |
| 166 | (after the RUN line): |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 167 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 168 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 169 | |
| 170 | define void @sub1(i32* %p, i32 %v) { |
| 171 | entry: |
| 172 | ; CHECK: sub1: |
| 173 | ; CHECK: subl |
| 174 | %0 = tail call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %p, i32 %v) |
| 175 | ret void |
| 176 | } |
| 177 | |
| 178 | define void @inc4(i64* %p) { |
| 179 | entry: |
| 180 | ; CHECK: inc4: |
| 181 | ; CHECK: incq |
| 182 | %0 = tail call i64 @llvm.atomic.load.add.i64.p0i64(i64* %p, i64 1) |
| 183 | ret void |
| 184 | } |
| 185 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 186 | Here you can see some "``CHECK:``" lines specified in comments. Now you can |
| 187 | see how the file is piped into ``llvm-as``, then ``llc``, and the machine code |
| 188 | output is what we are verifying. FileCheck checks the machine code output to |
| 189 | verify that it matches what the "``CHECK:``" lines specify. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 190 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 191 | The syntax of the "``CHECK:``" lines is very simple: they are fixed strings that |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 192 | must occur in order. FileCheck defaults to ignoring horizontal whitespace |
| 193 | differences (e.g. a space is allowed to match a tab) but otherwise, the contents |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 194 | of the "``CHECK:``" line is required to match some thing in the test file exactly. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 195 | |
| 196 | One nice thing about FileCheck (compared to grep) is that it allows merging |
| 197 | test cases together into logical groups. For example, because the test above |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 198 | is checking for the "``sub1:``" and "``inc4:``" labels, it will not match |
| 199 | unless there is a "``subl``" in between those labels. If it existed somewhere |
| 200 | else in the file, that would not count: "``grep subl``" matches if "``subl``" |
| 201 | exists anywhere in the file. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 202 | |
| 203 | The FileCheck -check-prefix option |
| 204 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 205 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 206 | The FileCheck `-check-prefix` option allows multiple test |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 207 | configurations to be driven from one `.ll` file. This is useful in many |
| 208 | circumstances, for example, testing different architectural variants with |
| 209 | :program:`llc`. Here's a simple example: |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 210 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 211 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 212 | |
| 213 | ; RUN: llvm-as < %s | llc -mtriple=i686-apple-darwin9 -mattr=sse41 \ |
Dmitri Gribenko | 19408a7 | 2012-06-12 00:48:47 +0000 | [diff] [blame] | 214 | ; RUN: | FileCheck %s -check-prefix=X32 |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 215 | ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin9 -mattr=sse41 \ |
Dmitri Gribenko | 19408a7 | 2012-06-12 00:48:47 +0000 | [diff] [blame] | 216 | ; RUN: | FileCheck %s -check-prefix=X64 |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 217 | |
| 218 | define <4 x i32> @pinsrd_1(i32 %s, <4 x i32> %tmp) nounwind { |
| 219 | %tmp1 = insertelement <4 x i32>; %tmp, i32 %s, i32 1 |
| 220 | ret <4 x i32> %tmp1 |
| 221 | ; X32: pinsrd_1: |
| 222 | ; X32: pinsrd $1, 4(%esp), %xmm0 |
| 223 | |
| 224 | ; X64: pinsrd_1: |
| 225 | ; X64: pinsrd $1, %edi, %xmm0 |
| 226 | } |
| 227 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 228 | In this case, we're testing that we get the expected code generation with |
| 229 | both 32-bit and 64-bit code generation. |
| 230 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 231 | The "CHECK-NEXT:" directive |
| 232 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 233 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 234 | Sometimes you want to match lines and would like to verify that matches |
| 235 | happen on exactly consecutive lines with no other lines in between them. In |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 236 | this case, you can use "``CHECK:``" and "``CHECK-NEXT:``" directives to specify |
| 237 | this. If you specified a custom check prefix, just use "``<PREFIX>-NEXT:``". |
| 238 | For example, something like this works as you'd expect: |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 239 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 240 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 241 | |
Dmitri Gribenko | 19408a7 | 2012-06-12 00:48:47 +0000 | [diff] [blame] | 242 | define void @t2(<2 x double>* %r, <2 x double>* %A, double %B) { |
| 243 | %tmp3 = load <2 x double>* %A, align 16 |
| 244 | %tmp7 = insertelement <2 x double> undef, double %B, i32 0 |
| 245 | %tmp9 = shufflevector <2 x double> %tmp3, |
| 246 | <2 x double> %tmp7, |
| 247 | <2 x i32> < i32 0, i32 2 > |
| 248 | store <2 x double> %tmp9, <2 x double>* %r, align 16 |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 249 | ret void |
| 250 | |
| 251 | ; CHECK: t2: |
| 252 | ; CHECK: movl 8(%esp), %eax |
| 253 | ; CHECK-NEXT: movapd (%eax), %xmm0 |
| 254 | ; CHECK-NEXT: movhpd 12(%esp), %xmm0 |
| 255 | ; CHECK-NEXT: movl 4(%esp), %eax |
| 256 | ; CHECK-NEXT: movapd %xmm0, (%eax) |
| 257 | ; CHECK-NEXT: ret |
| 258 | } |
| 259 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 260 | "``CHECK-NEXT:``" directives reject the input unless there is exactly one |
Eli Bendersky | 2fef6b6 | 2012-11-21 22:40:52 +0000 | [diff] [blame] | 261 | newline between it and the previous directive. A "``CHECK-NEXT:``" cannot be |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 262 | the first directive in a file. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 263 | |
Duncan P. N. Exon Smith | cffbbe9 | 2015-03-05 17:00:05 +0000 | [diff] [blame] | 264 | The "CHECK-SAME:" directive |
| 265 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 266 | |
| 267 | Sometimes you want to match lines and would like to verify that matches happen |
| 268 | on the same line as the previous match. In this case, you can use "``CHECK:``" |
| 269 | and "``CHECK-SAME:``" directives to specify this. If you specified a custom |
| 270 | check prefix, just use "``<PREFIX>-SAME:``". |
| 271 | |
| 272 | "``CHECK-SAME:``" is particularly powerful in conjunction with "``CHECK-NOT:``" |
| 273 | (described below). |
| 274 | |
| 275 | For example, the following works like you'd expect: |
| 276 | |
| 277 | .. code-block:: llvm |
| 278 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 279 | !0 = !DILocation(line: 5, scope: !1, inlinedAt: !2) |
Duncan P. N. Exon Smith | cffbbe9 | 2015-03-05 17:00:05 +0000 | [diff] [blame] | 280 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 281 | ; CHECK: !DILocation(line: 5, |
Duncan P. N. Exon Smith | cffbbe9 | 2015-03-05 17:00:05 +0000 | [diff] [blame] | 282 | ; CHECK-NOT: column: |
| 283 | ; CHECK-SAME: scope: ![[SCOPE:[0-9]+]] |
| 284 | |
| 285 | "``CHECK-SAME:``" directives reject the input if there are any newlines between |
| 286 | it and the previous directive. A "``CHECK-SAME:``" cannot be the first |
| 287 | directive in a file. |
| 288 | |
James Henderson | 5507f66 | 2018-06-26 15:15:45 +0000 | [diff] [blame] | 289 | The "CHECK-EMPTY:" directive |
James Henderson | c307b00 | 2018-06-26 15:29:09 +0000 | [diff] [blame] | 290 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
James Henderson | 5507f66 | 2018-06-26 15:15:45 +0000 | [diff] [blame] | 291 | |
| 292 | If you need to check that the next line has nothing on it, not even whitespace, |
| 293 | you can use the "``CHECK-EMPTY:``" directive. |
| 294 | |
| 295 | .. code-block:: llvm |
| 296 | |
Chandler Carruth | ef705b7 | 2018-08-06 01:41:25 +0000 | [diff] [blame] | 297 | declare void @foo() |
James Henderson | 5507f66 | 2018-06-26 15:15:45 +0000 | [diff] [blame] | 298 | |
Chandler Carruth | ef705b7 | 2018-08-06 01:41:25 +0000 | [diff] [blame] | 299 | declare void @bar() |
James Henderson | 5507f66 | 2018-06-26 15:15:45 +0000 | [diff] [blame] | 300 | ; CHECK: foo |
| 301 | ; CHECK-EMPTY: |
| 302 | ; CHECK-NEXT: bar |
| 303 | |
| 304 | Just like "``CHECK-NEXT:``" the directive will fail if there is more than one |
| 305 | newline before it finds the next blank line, and it cannot be the first |
| 306 | directive in a file. |
| 307 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 308 | The "CHECK-NOT:" directive |
| 309 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 310 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 311 | The "``CHECK-NOT:``" directive is used to verify that a string doesn't occur |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 312 | between two matches (or before the first match, or after the last match). For |
| 313 | example, to verify that a load is removed by a transformation, a test like this |
| 314 | can be used: |
| 315 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 316 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 317 | |
| 318 | define i8 @coerce_offset0(i32 %V, i32* %P) { |
| 319 | store i32 %V, i32* %P |
| 320 | |
| 321 | %P2 = bitcast i32* %P to i8* |
| 322 | %P3 = getelementptr i8* %P2, i32 2 |
| 323 | |
| 324 | %A = load i8* %P3 |
| 325 | ret i8 %A |
| 326 | ; CHECK: @coerce_offset0 |
| 327 | ; CHECK-NOT: load |
| 328 | ; CHECK: ret i8 |
| 329 | } |
| 330 | |
Fedor Sergeev | 6c9e19b | 2018-11-13 00:46:13 +0000 | [diff] [blame] | 331 | The "CHECK-COUNT:" directive |
Fedor Sergeev | 5bf0c15 | 2018-11-13 01:12:19 +0000 | [diff] [blame] | 332 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Fedor Sergeev | 6c9e19b | 2018-11-13 00:46:13 +0000 | [diff] [blame] | 333 | |
| 334 | If you need to match multiple lines with the same pattern over and over again |
| 335 | you can repeat a plain ``CHECK:`` as many times as needed. If that looks too |
| 336 | boring you can instead use a counted check "``CHECK-COUNT-<num>:``", where |
| 337 | ``<num>`` is a positive decimal number. It will match the pattern exactly |
| 338 | ``<num>`` times, no more and no less. If you specified a custom check prefix, |
| 339 | just use "``<PREFIX>-COUNT-<num>:``" for the same effect. |
| 340 | Here is a simple example: |
| 341 | |
Fedor Sergeev | 8b07812 | 2018-11-13 05:47:01 +0000 | [diff] [blame] | 342 | .. code-block:: text |
Fedor Sergeev | 6c9e19b | 2018-11-13 00:46:13 +0000 | [diff] [blame] | 343 | |
| 344 | Loop at depth 1 |
| 345 | Loop at depth 1 |
| 346 | Loop at depth 1 |
| 347 | Loop at depth 1 |
| 348 | Loop at depth 2 |
| 349 | Loop at depth 3 |
| 350 | |
| 351 | ; CHECK-COUNT-6: Loop at depth {{[0-9]+}} |
| 352 | ; CHECK-NOT: Loop at depth {{[0-9]+}} |
| 353 | |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 354 | The "CHECK-DAG:" directive |
| 355 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 356 | |
| 357 | If it's necessary to match strings that don't occur in a strictly sequential |
| 358 | order, "``CHECK-DAG:``" could be used to verify them between two matches (or |
| 359 | before the first match, or after the last match). For example, clang emits |
| 360 | vtable globals in reverse order. Using ``CHECK-DAG:``, we can keep the checks |
| 361 | in the natural order: |
| 362 | |
| 363 | .. code-block:: c++ |
| 364 | |
| 365 | // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s |
| 366 | |
| 367 | struct Foo { virtual void method(); }; |
| 368 | Foo f; // emit vtable |
| 369 | // CHECK-DAG: @_ZTV3Foo = |
| 370 | |
| 371 | struct Bar { virtual void method(); }; |
| 372 | Bar b; |
| 373 | // CHECK-DAG: @_ZTV3Bar = |
| 374 | |
Renato Golin | 58ab84a | 2013-10-11 18:50:22 +0000 | [diff] [blame] | 375 | ``CHECK-NOT:`` directives could be mixed with ``CHECK-DAG:`` directives to |
| 376 | exclude strings between the surrounding ``CHECK-DAG:`` directives. As a result, |
| 377 | the surrounding ``CHECK-DAG:`` directives cannot be reordered, i.e. all |
| 378 | occurrences matching ``CHECK-DAG:`` before ``CHECK-NOT:`` must not fall behind |
| 379 | occurrences matching ``CHECK-DAG:`` after ``CHECK-NOT:``. For example, |
| 380 | |
| 381 | .. code-block:: llvm |
| 382 | |
| 383 | ; CHECK-DAG: BEFORE |
| 384 | ; CHECK-NOT: NOT |
| 385 | ; CHECK-DAG: AFTER |
| 386 | |
| 387 | This case will reject input strings where ``BEFORE`` occurs after ``AFTER``. |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 388 | |
| 389 | With captured variables, ``CHECK-DAG:`` is able to match valid topological |
| 390 | orderings of a DAG with edges from the definition of a variable to its use. |
| 391 | It's useful, e.g., when your test cases need to match different output |
| 392 | sequences from the instruction scheduler. For example, |
| 393 | |
| 394 | .. code-block:: llvm |
| 395 | |
| 396 | ; CHECK-DAG: add [[REG1:r[0-9]+]], r1, r2 |
| 397 | ; CHECK-DAG: add [[REG2:r[0-9]+]], r3, r4 |
| 398 | ; CHECK: mul r5, [[REG1]], [[REG2]] |
| 399 | |
| 400 | In this case, any order of that two ``add`` instructions will be allowed. |
| 401 | |
Renato Golin | 58ab84a | 2013-10-11 18:50:22 +0000 | [diff] [blame] | 402 | If you are defining `and` using variables in the same ``CHECK-DAG:`` block, |
| 403 | be aware that the definition rule can match `after` its use. |
| 404 | |
| 405 | So, for instance, the code below will pass: |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 406 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 407 | .. code-block:: text |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 408 | |
Renato Golin | 58ab84a | 2013-10-11 18:50:22 +0000 | [diff] [blame] | 409 | ; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0] |
| 410 | ; CHECK-DAG: vmov.32 [[REG2]][1] |
| 411 | vmov.32 d0[1] |
| 412 | vmov.32 d0[0] |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 413 | |
Renato Golin | 58ab84a | 2013-10-11 18:50:22 +0000 | [diff] [blame] | 414 | While this other code, will not: |
| 415 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 416 | .. code-block:: text |
Renato Golin | 58ab84a | 2013-10-11 18:50:22 +0000 | [diff] [blame] | 417 | |
| 418 | ; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0] |
| 419 | ; CHECK-DAG: vmov.32 [[REG2]][1] |
| 420 | vmov.32 d1[1] |
| 421 | vmov.32 d0[0] |
| 422 | |
| 423 | While this can be very useful, it's also dangerous, because in the case of |
| 424 | register sequence, you must have a strong order (read before write, copy before |
| 425 | use, etc). If the definition your test is looking for doesn't match (because |
| 426 | of a bug in the compiler), it may match further away from the use, and mask |
| 427 | real bugs away. |
| 428 | |
| 429 | In those cases, to enforce the order, use a non-DAG directive between DAG-blocks. |
Michael Liao | 91a1b2c | 2013-05-14 20:34:12 +0000 | [diff] [blame] | 430 | |
Joel E. Denny | bcf5b44 | 2018-07-11 20:27:27 +0000 | [diff] [blame] | 431 | A ``CHECK-DAG:`` directive skips matches that overlap the matches of any |
| 432 | preceding ``CHECK-DAG:`` directives in the same ``CHECK-DAG:`` block. Not only |
| 433 | is this non-overlapping behavior consistent with other directives, but it's |
| 434 | also necessary to handle sets of non-unique strings or patterns. For example, |
| 435 | the following directives look for unordered log entries for two tasks in a |
| 436 | parallel program, such as the OpenMP runtime: |
| 437 | |
| 438 | .. code-block:: text |
| 439 | |
| 440 | // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin |
| 441 | // CHECK-DAG: [[THREAD_ID]]: task_end |
| 442 | // |
| 443 | // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin |
| 444 | // CHECK-DAG: [[THREAD_ID]]: task_end |
| 445 | |
| 446 | The second pair of directives is guaranteed not to match the same log entries |
| 447 | as the first pair even though the patterns are identical and even if the text |
| 448 | of the log entries is identical because the thread ID manages to be reused. |
| 449 | |
Stephen Lin | f8bd2e5 | 2013-07-12 14:51:05 +0000 | [diff] [blame] | 450 | The "CHECK-LABEL:" directive |
Bill Wendling | c02da46 | 2013-07-30 08:26:24 +0000 | [diff] [blame] | 451 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Stephen Lin | f8bd2e5 | 2013-07-12 14:51:05 +0000 | [diff] [blame] | 452 | |
| 453 | Sometimes in a file containing multiple tests divided into logical blocks, one |
| 454 | or more ``CHECK:`` directives may inadvertently succeed by matching lines in a |
| 455 | later block. While an error will usually eventually be generated, the check |
| 456 | flagged as causing the error may not actually bear any relationship to the |
| 457 | actual source of the problem. |
| 458 | |
| 459 | In order to produce better error messages in these cases, the "``CHECK-LABEL:``" |
| 460 | directive can be used. It is treated identically to a normal ``CHECK`` |
Stephen Lin | b946407 | 2013-07-18 23:26:58 +0000 | [diff] [blame] | 461 | directive except that FileCheck makes an additional assumption that a line |
| 462 | matched by the directive cannot also be matched by any other check present in |
| 463 | ``match-filename``; this is intended to be used for lines containing labels or |
| 464 | other unique identifiers. Conceptually, the presence of ``CHECK-LABEL`` divides |
| 465 | the input stream into separate blocks, each of which is processed independently, |
| 466 | preventing a ``CHECK:`` directive in one block matching a line in another block. |
Artem Belevich | f55e72a | 2017-03-09 17:59:04 +0000 | [diff] [blame] | 467 | If ``--enable-var-scope`` is in effect, all local variables are cleared at the |
| 468 | beginning of the block. |
| 469 | |
Stephen Lin | b946407 | 2013-07-18 23:26:58 +0000 | [diff] [blame] | 470 | For example, |
Stephen Lin | f8bd2e5 | 2013-07-12 14:51:05 +0000 | [diff] [blame] | 471 | |
| 472 | .. code-block:: llvm |
| 473 | |
| 474 | define %struct.C* @C_ctor_base(%struct.C* %this, i32 %x) { |
| 475 | entry: |
| 476 | ; CHECK-LABEL: C_ctor_base: |
| 477 | ; CHECK: mov [[SAVETHIS:r[0-9]+]], r0 |
| 478 | ; CHECK: bl A_ctor_base |
| 479 | ; CHECK: mov r0, [[SAVETHIS]] |
| 480 | %0 = bitcast %struct.C* %this to %struct.A* |
| 481 | %call = tail call %struct.A* @A_ctor_base(%struct.A* %0) |
| 482 | %1 = bitcast %struct.C* %this to %struct.B* |
| 483 | %call2 = tail call %struct.B* @B_ctor_base(%struct.B* %1, i32 %x) |
| 484 | ret %struct.C* %this |
| 485 | } |
| 486 | |
| 487 | define %struct.D* @D_ctor_base(%struct.D* %this, i32 %x) { |
| 488 | entry: |
| 489 | ; CHECK-LABEL: D_ctor_base: |
| 490 | |
| 491 | The use of ``CHECK-LABEL:`` directives in this case ensures that the three |
| 492 | ``CHECK:`` directives only accept lines corresponding to the body of the |
| 493 | ``@C_ctor_base`` function, even if the patterns match lines found later in |
Stephen Lin | b946407 | 2013-07-18 23:26:58 +0000 | [diff] [blame] | 494 | the file. Furthermore, if one of these three ``CHECK:`` directives fail, |
| 495 | FileCheck will recover by continuing to the next block, allowing multiple test |
| 496 | failures to be detected in a single invocation. |
Stephen Lin | f8bd2e5 | 2013-07-12 14:51:05 +0000 | [diff] [blame] | 497 | |
| 498 | There is no requirement that ``CHECK-LABEL:`` directives contain strings that |
| 499 | correspond to actual syntactic labels in a source or output language: they must |
| 500 | simply uniquely match a single line in the file being verified. |
| 501 | |
| 502 | ``CHECK-LABEL:`` directives cannot contain variable definitions or uses. |
| 503 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 504 | FileCheck Regex Matching Syntax |
| 505 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 506 | |
Paul Robinson | 282b3d3 | 2015-03-05 23:04:26 +0000 | [diff] [blame] | 507 | All FileCheck directives take a pattern to match. |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 508 | For most uses of FileCheck, fixed string matching is perfectly sufficient. For |
| 509 | some things, a more flexible form of matching is desired. To support this, |
| 510 | FileCheck allows you to specify regular expressions in matching strings, |
Sjoerd Meijer | 9a26a7e | 2017-10-13 14:02:36 +0000 | [diff] [blame] | 511 | surrounded by double braces: ``{{yourregex}}``. FileCheck implements a POSIX |
| 512 | regular expression matcher; it supports Extended POSIX regular expressions |
| 513 | (ERE). Because we want to use fixed string matching for a majority of what we |
| 514 | do, FileCheck has been designed to support mixing and matching fixed string |
| 515 | matching with regular expressions. This allows you to write things like this: |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 516 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 517 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 518 | |
| 519 | ; CHECK: movhpd {{[0-9]+}}(%esp), {{%xmm[0-7]}} |
| 520 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 521 | In this case, any offset from the ESP register will be allowed, and any xmm |
| 522 | register will be allowed. |
| 523 | |
| 524 | Because regular expressions are enclosed with double braces, they are |
| 525 | visually distinct, and you don't need to use escape characters within the double |
| 526 | braces like you would in C. In the rare case that you want to match double |
| 527 | braces explicitly from the input, you can use something ugly like |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 528 | ``{{[{][{]}}`` as your pattern. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 529 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 530 | FileCheck String Substitution Blocks |
| 531 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 532 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 533 | It is often useful to match a pattern and then verify that it occurs again |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 534 | later in the file. For codegen tests, this can be useful to allow any |
| 535 | register, but verify that that register is used consistently later. To do |
| 536 | this, :program:`FileCheck` supports string substitution blocks that allow |
| 537 | string variables to be defined and substituted into patterns. Here is a simple |
| 538 | example: |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 539 | |
Dmitri Gribenko | a99fa5b | 2012-06-12 15:45:07 +0000 | [diff] [blame] | 540 | .. code-block:: llvm |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 541 | |
| 542 | ; CHECK: test5: |
| 543 | ; CHECK: notw [[REGISTER:%[a-z]+]] |
Chad Rosier | fd7469c | 2012-05-24 21:17:47 +0000 | [diff] [blame] | 544 | ; CHECK: andw {{.*}}[[REGISTER]] |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 545 | |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 546 | The first check line matches a regex ``%[a-z]+`` and captures it into the |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 547 | string variable ``REGISTER``. The second line verifies that whatever is in |
| 548 | ``REGISTER`` occurs later in the file after an "``andw``". :program:`FileCheck` |
| 549 | string substitution blocks are always contained in ``[[ ]]`` pairs, and string |
| 550 | variable names can be formed with the regex ``[a-zA-Z_][a-zA-Z0-9_]*``. If a |
| 551 | colon follows the name, then it is a definition of the variable; otherwise, it |
| 552 | is a substitution. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 553 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 554 | :program:`FileCheck` variables can be defined multiple times, and substitutions |
| 555 | always get the latest value. Variables can also be substituted later on the |
| 556 | same line they were defined on. For example: |
Eli Bendersky | 4ca99ba | 2012-12-01 22:03:57 +0000 | [diff] [blame] | 557 | |
| 558 | .. code-block:: llvm |
| 559 | |
| 560 | ; CHECK: op [[REG:r[0-9]+]], [[REG]] |
| 561 | |
| 562 | Can be useful if you want the operands of ``op`` to be the same register, |
| 563 | and don't care exactly which register it is. |
Dmitri Gribenko | a72e9f0 | 2012-11-14 19:42:32 +0000 | [diff] [blame] | 564 | |
Artem Belevich | f55e72a | 2017-03-09 17:59:04 +0000 | [diff] [blame] | 565 | If ``--enable-var-scope`` is in effect, variables with names that |
| 566 | start with ``$`` are considered to be global. All others variables are |
| 567 | local. All local variables get undefined at the beginning of each |
| 568 | CHECK-LABEL block. Global variables are not affected by CHECK-LABEL. |
| 569 | This makes it easier to ensure that individual tests are not affected |
| 570 | by variables set in preceding tests. |
| 571 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 572 | FileCheck Numeric Substitution Blocks |
| 573 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 574 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 575 | :program:`FileCheck` also supports numeric substitution blocks that allow |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 576 | defining numeric variables and checking for numeric values that satisfy a |
| 577 | numeric expression constraint based on those variables via a numeric |
| 578 | substitution. This allows ``CHECK:`` directives to verify a numeric relation |
| 579 | between two numbers, such as the need for consecutive registers to be used. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 580 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 581 | The syntax to define a numeric variable is ``[[#<NUMVAR>:]]`` where |
| 582 | ``<NUMVAR>`` is the name of the numeric variable to define to the matching |
| 583 | value. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 584 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 585 | For example: |
| 586 | |
| 587 | .. code-block:: llvm |
| 588 | |
| 589 | ; CHECK: mov r[[#REG:]], 42 |
| 590 | |
| 591 | would match ``mov r5, 42`` and set ``REG`` to the value ``5``. |
| 592 | |
| 593 | The syntax of a numeric substitution is ``[[#<NUMVAR><op><offset>]]`` where: |
| 594 | |
| 595 | * ``<NUMVAR>`` is the name of a defined numeric variable. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 596 | |
Thomas Preud'homme | a2ef1ba | 2019-06-19 23:47:24 +0000 | [diff] [blame] | 597 | * ``<op>`` is an optional operation to perform on the value of ``<NUMVAR>``. |
| 598 | Currently supported operations are ``+`` and ``-``. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 599 | |
| 600 | * ``<offset>`` is the immediate value that constitutes the second operand of |
Thomas Preud'homme | a2ef1ba | 2019-06-19 23:47:24 +0000 | [diff] [blame] | 601 | the operation ``<op>``. It must be present if ``<op>`` is present, absent |
| 602 | otherwise. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 603 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 604 | Spaces are accepted before, after and between any of these elements. |
| 605 | |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 606 | For example: |
| 607 | |
| 608 | .. code-block:: llvm |
| 609 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 610 | ; CHECK: load r[[#REG:]], [r0] |
| 611 | ; CHECK: load r[[#REG+1]], [r1] |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 612 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 613 | The above example would match the text: |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 614 | |
Thomas Preud'homme | 5c15dba | 2019-05-15 15:20:45 +0000 | [diff] [blame] | 615 | .. code-block:: gas |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 616 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 617 | load r5, [r0] |
| 618 | load r6, [r1] |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 619 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 620 | but would not match the text: |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 621 | |
Thomas Preud'homme | 5c15dba | 2019-05-15 15:20:45 +0000 | [diff] [blame] | 622 | .. code-block:: gas |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 623 | |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 624 | load r5, [r0] |
| 625 | load r7, [r1] |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 626 | |
| 627 | due to ``7`` being unequal to ``5 + 1``. |
| 628 | |
| 629 | The ``--enable-var-scope`` option has the same effect on numeric variables as |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 630 | on string variables. |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 631 | |
Thomas Preud'homme | a2ef1ba | 2019-06-19 23:47:24 +0000 | [diff] [blame] | 632 | Important note: In its current implementation, an expression cannot use a |
| 633 | numeric variable defined on the same line. |
Thomas Preud'homme | 71d3f22 | 2019-06-06 13:21:06 +0000 | [diff] [blame] | 634 | |
Thomas Preud'homme | 7b4ecdd | 2019-05-14 11:58:30 +0000 | [diff] [blame] | 635 | FileCheck Pseudo Numeric Variables |
| 636 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Alexander Kornienko | 92987fb | 2012-11-14 21:07:37 +0000 | [diff] [blame] | 637 | |
Thomas Preud'homme | 288ed91 | 2019-05-02 00:04:38 +0000 | [diff] [blame] | 638 | Sometimes there's a need to verify output that contains line numbers of the |
Dmitri Gribenko | f589e24 | 2012-11-29 19:21:02 +0000 | [diff] [blame] | 639 | match file, e.g. when testing compiler diagnostics. This introduces a certain |
| 640 | fragility of the match file structure, as "``CHECK:``" lines contain absolute |
| 641 | line numbers in the same file, which have to be updated whenever line numbers |
| 642 | change due to text addition or deletion. |
Alexander Kornienko | 92987fb | 2012-11-14 21:07:37 +0000 | [diff] [blame] | 643 | |
Thomas Preud'homme | a2ef1ba | 2019-06-19 23:47:24 +0000 | [diff] [blame] | 644 | To support this case, FileCheck expressions understand the ``@LINE`` pseudo |
| 645 | numeric variable which evaluates to the line number of the CHECK pattern where |
| 646 | it is found. |
Alexander Kornienko | 92987fb | 2012-11-14 21:07:37 +0000 | [diff] [blame] | 647 | |
| 648 | This way match patterns can be put near the relevant test lines and include |
| 649 | relative line number references, for example: |
| 650 | |
| 651 | .. code-block:: c++ |
| 652 | |
Thomas Preud'homme | 288ed91 | 2019-05-02 00:04:38 +0000 | [diff] [blame] | 653 | // CHECK: test.cpp:[[# @LINE + 4]]:6: error: expected ';' after top level declarator |
Alexander Kornienko | 92987fb | 2012-11-14 21:07:37 +0000 | [diff] [blame] | 654 | // CHECK-NEXT: {{^int a}} |
| 655 | // CHECK-NEXT: {{^ \^}} |
| 656 | // CHECK-NEXT: {{^ ;}} |
| 657 | int a |
| 658 | |
Thomas Preud'homme | 1a944d2 | 2019-05-23 00:10:14 +0000 | [diff] [blame] | 659 | To support legacy uses of ``@LINE`` as a special string variable, |
| 660 | :program:`FileCheck` also accepts the following uses of ``@LINE`` with string |
| 661 | substitution block syntax: ``[[@LINE]]``, ``[[@LINE+<offset>]]`` and |
Thomas Preud'homme | 288ed91 | 2019-05-02 00:04:38 +0000 | [diff] [blame] | 662 | ``[[@LINE-<offset>]]`` without any spaces inside the brackets and where |
| 663 | ``offset`` is an integer. |
| 664 | |
Wolfgang Pieb | 0b4509e | 2016-06-27 23:59:00 +0000 | [diff] [blame] | 665 | Matching Newline Characters |
| 666 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 667 | |
| 668 | To match newline characters in regular expressions the character class |
| 669 | ``[[:space:]]`` can be used. For example, the following pattern: |
| 670 | |
| 671 | .. code-block:: c++ |
| 672 | |
| 673 | // CHECK: DW_AT_location [DW_FORM_sec_offset] ([[DLOC:0x[0-9a-f]+]]){{[[:space:]].*}}"intd" |
| 674 | |
| 675 | matches output of the form (from llvm-dwarfdump): |
| 676 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 677 | .. code-block:: text |
Wolfgang Pieb | 0b4509e | 2016-06-27 23:59:00 +0000 | [diff] [blame] | 678 | |
| 679 | DW_AT_location [DW_FORM_sec_offset] (0x00000233) |
| 680 | DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c9] = "intd") |
| 681 | |
| 682 | letting us set the :program:`FileCheck` variable ``DLOC`` to the desired value |
| 683 | ``0x00000233``, extracted from the line immediately preceding "``intd``". |