1FILECHECK(1)                         LLVM                         FILECHECK(1)
2
3
4

NAME

6       FileCheck - Flexible pattern matching file verifier
7

SYNOPSIS

9       FileCheck match-filename [--check-prefix=XXX] [--strict-whitespace]
10

DESCRIPTION

12       FileCheck  reads  two files (one from standard input, and one specified
13       on the command line) and uses one to verify the other.   This  behavior
14       is  particularly  useful  for the testsuite, which wants to verify that
15       the output of some tool (e.g. llc) contains  the  expected  information
16       (for  example,  a  movsd from esp or whatever is interesting).  This is
17       similar to using grep, but it is optimized for matching  multiple  dif‐
18       ferent inputs in one file in a specific order.
19
20       The  match-filename  file specifies the file that contains the patterns
21       to match.  The file to verify is read from standard  input  unless  the
22       --input-file option is used.
23

OPTIONS

25       Options  are  parsed  from  the environment variable FILECHECK_OPTS and
26       from the command line.
27
28       -help  Print a summary of command line options.
29
30       --check-prefix prefix
31              FileCheck searches the contents of match-filename  for  patterns
32              to   match.   By  default,  these  patterns  are  prefixed  with
33              "CHECK:".  If you'd like to use a different prefix (e.g. because
34              the  same  input  file  is  checking  multiple different tool or
35              options), the --check-prefix argument allows you to specify  one
36              or  more  prefixes  to  match.  Multiple prefixes are useful for
37              tests which might change for different  run  options,  but  most
38              lines remain the same.
39
40       --check-prefixes prefix1,prefix2,...
41              An  alias  of --check-prefix that allows multiple prefixes to be
42              specified as a comma separated list.
43
44       --input-file filename
45              File to check (defaults to stdin).
46
47       --match-full-lines
48              By default, FileCheck allows matches of anywhere on a line. This
49              option  will  require  all  positive  matches to cover an entire
50              line.  Leading  and  trailing  whitespace  is  ignored,   unless
51              --strict-whitespace  is  also specified. (Note: negative matches
52              from CHECK-NOT are not affected by this option!)
53
54              Passing this option is equivalent to inserting {{^ *}} or  {{^}}
55              before, and {{ *$}} or {{$}} after every positive check pattern.
56
57       --strict-whitespace
58              By  default, FileCheck canonicalizes input horizontal whitespace
59              (spaces and tabs) which causes it to ignore these differences (a
60              space  will match a tab).  The --strict-whitespace argument dis‐
61              ables this behavior. End-of-line sequences are canonicalized  to
62              UNIX-style \n in all modes.
63
64       --implicit-check-not check-pattern
65              Adds implicit negative checks for the specified patterns between
66              positive checks. The option allows writing stricter tests  with‐
67              out stuffing them with CHECK-NOTs.
68
69              For  example, "--implicit-check-not warning:" can be useful when
70              testing diagnostic messages from tools that don't have an option
71              similar to clang -verify. With this option FileCheck will verify
72              that input does not contain warnings not covered by  any  CHECK:
73              patterns.
74
75       --dump-input <mode>
76              Dump  input to stderr, adding annotations representing currently
77              enabled diagnostics.  Do this either  'always',  on  'fail',  or
78              'never'.  Specify 'help' to explain the dump format and quit.
79
80       --dump-input-on-failure
81              When  the  check  fails,  dump  all of the original input.  This
82              option is deprecated in favor of --dump-input=fail.
83
84       --enable-var-scope
85              Enables scope for regex variables.
86
87              Variables with names that start with $ are considered global and
88              remain set throughout the file.
89
90              All   other  variables  get  undefined  after  each  encountered
91              CHECK-LABEL.
92
93       -D<VAR=VALUE>
94              Sets a filecheck variable VAR with value VALUE that can be  used
95              in CHECK: lines.
96
97       -version
98              Show the version number of this program.
99
100       -v     Print directive pattern matches.
101
102       -vv    Print  information  helpful  in  diagnosing  internal  FileCheck
103              issues,  such  as  discarded  overlapping  CHECK-DAG:   matches,
104              implicit  EOF  pattern  matches, and CHECK-NOT: patterns that do
105              not have matches.  Implies -v.
106
107       --allow-deprecated-dag-overlap
108              Enable overlapping among  matches  in  a  group  of  consecutive
109              CHECK-DAG:  directives.   This  option is deprecated and is only
110              provided for convenience as old tests are migrated  to  the  new
111              non-overlapping CHECK-DAG: implementation.
112
113       --color
114              Use colors in output (autodetected by default).
115

EXIT STATUS

117       If  FileCheck  verifies that the file matches the expected contents, it
118       exits with 0.  Otherwise, if not, or if an error occurs, it  will  exit
119       with a non-zero value.
120

TUTORIAL

122       FileCheck  is  typically used from LLVM regression tests, being invoked
123       on the RUN line of the test.  A simple example of using FileCheck  from
124       a RUN line looks like this:
125
126          ; RUN: llvm-as < %s | llc -march=x86-64 | FileCheck %s
127
128       This  syntax  says  to  pipe the current file ("%s") into llvm-as, pipe
129       that into llc, then pipe the output of llc into FileCheck.  This  means
130       that  FileCheck  will  be verifying its standard input (the llc output)
131       against the filename argument specified (the original .ll  file  speci‐
132       fied  by  "%s").   To see how this works, let's look at the rest of the
133       .ll file (after the RUN line):
134
135          define void @sub1(i32* %p, i32 %v) {
136          entry:
137          ; CHECK: sub1:
138          ; CHECK: subl
139                  %0 = tail call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %p, i32 %v)
140                  ret void
141          }
142
143          define void @inc4(i64* %p) {
144          entry:
145          ; CHECK: inc4:
146          ; CHECK: incq
147                  %0 = tail call i64 @llvm.atomic.load.add.i64.p0i64(i64* %p, i64 1)
148                  ret void
149          }
150
151       Here you can see some "CHECK:" lines specified in  comments.   Now  you
152       can  see  how the file is piped into llvm-as, then llc, and the machine
153       code output is what we are verifying.   FileCheck  checks  the  machine
154       code output to verify that it matches what the "CHECK:" lines specify.
155
156       The syntax of the "CHECK:" lines is very simple: they are fixed strings
157       that must occur in order.  FileCheck defaults  to  ignoring  horizontal
158       whitespace  differences  (e.g.  a  space is allowed to match a tab) but
159       otherwise, the contents of the "CHECK:" line is required to match  some
160       thing in the test file exactly.
161
162       One  nice  thing  about  FileCheck (compared to grep) is that it allows
163       merging test cases together into logical groups.  For example,  because
164       the  test above is checking for the "sub1:" and "inc4:" labels, it will
165       not match unless there is a "subl" in  between  those  labels.   If  it
166       existed  somewhere  else in the file, that would not count: "grep subl"
167       matches if "subl" exists anywhere in the file.
168
169   The FileCheck -check-prefix option
170       The FileCheck -check-prefix option allows multiple test  configurations
171       to  be driven from one .ll file.  This is useful in many circumstances,
172       for example, testing different architectural variants with llc.  Here's
173       a simple example:
174
175          ; RUN: llvm-as < %s | llc -mtriple=i686-apple-darwin9 -mattr=sse41 \
176          ; RUN:              | FileCheck %s -check-prefix=X32
177          ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin9 -mattr=sse41 \
178          ; RUN:              | FileCheck %s -check-prefix=X64
179
180          define <4 x i32> @pinsrd_1(i32 %s, <4 x i32> %tmp) nounwind {
181                  %tmp1 = insertelement <4 x i32>; %tmp, i32 %s, i32 1
182                  ret <4 x i32> %tmp1
183          ; X32: pinsrd_1:
184          ; X32:    pinsrd $1, 4(%esp), %xmm0
185
186          ; X64: pinsrd_1:
187          ; X64:    pinsrd $1, %edi, %xmm0
188          }
189
190       In  this  case,  we're testing that we get the expected code generation
191       with both 32-bit and 64-bit code generation.
192
193   The CHECK-NEXT: directive
194       Sometimes you want to match lines and would like to verify that matches
195       happen  on  exactly  consecutive  lines  with no other lines in between
196       them.  In this case, you can use "CHECK:" and "CHECK-NEXT:"  directives
197       to  specify  this.   If  you  specified a custom check prefix, just use
198       "<PREFIX>-NEXT:".  For example, something  like  this  works  as  you'd
199       expect:
200
201          define void @t2(<2 x double>* %r, <2 x double>* %A, double %B) {
202               %tmp3 = load <2 x double>* %A, align 16
203               %tmp7 = insertelement <2 x double> undef, double %B, i32 0
204               %tmp9 = shufflevector <2 x double> %tmp3,
205                                      <2 x double> %tmp7,
206                                      <2 x i32> < i32 0, i32 2 >
207               store <2 x double> %tmp9, <2 x double>* %r, align 16
208               ret void
209
210          ; CHECK:          t2:
211          ; CHECK:             movl    8(%esp), %eax
212          ; CHECK-NEXT:        movapd  (%eax), %xmm0
213          ; CHECK-NEXT:        movhpd  12(%esp), %xmm0
214          ; CHECK-NEXT:        movl    4(%esp), %eax
215          ; CHECK-NEXT:        movapd  %xmm0, (%eax)
216          ; CHECK-NEXT:        ret
217          }
218
219       "CHECK-NEXT:"  directives  reject the input unless there is exactly one
220       newline between it and the previous directive.  A "CHECK-NEXT:"  cannot
221       be the first directive in a file.
222
223   The CHECK-SAME: directive
224       Sometimes you want to match lines and would like to verify that matches
225       happen on the same line as the previous match.  In this case,  you  can
226       use  "CHECK:"  and  "CHECK-SAME:"  directives  to specify this.  If you
227       specified a custom check prefix, just use "<PREFIX>-SAME:".
228
229       "CHECK-SAME:" is particularly powerful in conjunction with "CHECK-NOT:"
230       (described below).
231
232       For example, the following works like you'd expect:
233
234          !0 = !DILocation(line: 5, scope: !1, inlinedAt: !2)
235
236          ; CHECK:       !DILocation(line: 5,
237          ; CHECK-NOT:               column:
238          ; CHECK-SAME:              scope: ![[SCOPE:[0-9]+]]
239
240       "CHECK-SAME:"  directives  reject  the  input if there are any newlines
241       between it and the previous directive.  A "CHECK-SAME:" cannot  be  the
242       first directive in a file.
243
244   The CHECK-EMPTY: directive
245       If  you  need  to  check that the next line has nothing on it, not even
246       whitespace, you can use the "CHECK-EMPTY:" directive.
247
248          declare void @foo()
249
250          declare void @bar()
251          ; CHECK: foo
252          ; CHECK-EMPTY:
253          ; CHECK-NEXT: bar
254
255       Just like "CHECK-NEXT:" the directive will fail if there is  more  than
256       one  newline  before it finds the next blank line, and it cannot be the
257       first directive in a file.
258
259   The CHECK-NOT: directive
260       The "CHECK-NOT:" directive is used to  verify  that  a  string  doesn't
261       occur between two matches (or before the first match, or after the last
262       match).  For example, to verify that a load is removed by a transforma‐
263       tion, a test like this can be used:
264
265          define i8 @coerce_offset0(i32 %V, i32* %P) {
266            store i32 %V, i32* %P
267
268            %P2 = bitcast i32* %P to i8*
269            %P3 = getelementptr i8* %P2, i32 2
270
271            %A = load i8* %P3
272            ret i8 %A
273          ; CHECK: @coerce_offset0
274          ; CHECK-NOT: load
275          ; CHECK: ret i8
276          }
277
278   The CHECK-COUNT: directive
279       If you need to match multiple lines with the same pattern over and over
280       again you can repeat a plain CHECK: as many times as  needed.  If  that
281       looks    too   boring   you   can   instead   use   a   counted   check
282       "CHECK-COUNT-<num>:", where <num> is a positive decimal number. It will
283       match  the  pattern  exactly  <num>  times, no more and no less. If you
284       specified a custom check prefix, just use  "<PREFIX>-COUNT-<num>:"  for
285       the same effect.  Here is a simple example:
286
287          Loop at depth 1
288          Loop at depth 1
289          Loop at depth 1
290          Loop at depth 1
291            Loop at depth 2
292              Loop at depth 3
293
294          ; CHECK-COUNT-6: Loop at depth {{[0-9]+}}
295          ; CHECK-NOT:     Loop at depth {{[0-9]+}}
296
297   The CHECK-DAG: directive
298       If  it's  necessary  to  match  strings  that don't occur in a strictly
299       sequential order, "CHECK-DAG:" could be used to verify them between two
300       matches (or before the first match, or after the last match). For exam‐
301       ple, clang emits vtable globals in reverse order. Using CHECK-DAG:,  we
302       can keep the checks in the natural order:
303
304          // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
305
306          struct Foo { virtual void method(); };
307          Foo f;  // emit vtable
308          // CHECK-DAG: @_ZTV3Foo =
309
310          struct Bar { virtual void method(); };
311          Bar b;
312          // CHECK-DAG: @_ZTV3Bar =
313
314       CHECK-NOT:  directives  could  be  mixed  with CHECK-DAG: directives to
315       exclude strings between the surrounding  CHECK-DAG:  directives.  As  a
316       result, the surrounding CHECK-DAG: directives cannot be reordered, i.e.
317       all occurrences matching CHECK-DAG: before  CHECK-NOT:  must  not  fall
318       behind occurrences matching CHECK-DAG: after CHECK-NOT:. For example,
319
320          ; CHECK-DAG: BEFORE
321          ; CHECK-NOT: NOT
322          ; CHECK-DAG: AFTER
323
324       This case will reject input strings where BEFORE occurs after AFTER.
325
326       With  captured variables, CHECK-DAG: is able to match valid topological
327       orderings of a DAG with edges from the definition of a variable to  its
328       use.   It's  useful, e.g., when your test cases need to match different
329       output sequences from the instruction scheduler. For example,
330
331          ; CHECK-DAG: add [[REG1:r[0-9]+]], r1, r2
332          ; CHECK-DAG: add [[REG2:r[0-9]+]], r3, r4
333          ; CHECK:     mul r5, [[REG1]], [[REG2]]
334
335       In this case, any order of that two add instructions will be allowed.
336
337       If you are defining and using variables in the same  CHECK-DAG:  block,
338       be aware that the definition rule can match after its use.
339
340       So, for instance, the code below will pass:
341
342          ; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0]
343          ; CHECK-DAG: vmov.32 [[REG2]][1]
344          vmov.32 d0[1]
345          vmov.32 d0[0]
346
347       While this other code, will not:
348
349          ; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0]
350          ; CHECK-DAG: vmov.32 [[REG2]][1]
351          vmov.32 d1[1]
352          vmov.32 d0[0]
353
354       While this can be very useful, it's also dangerous, because in the case
355       of register sequence, you must have a strong order (read before  write,
356       copy  before  use,  etc).  If  the  definition your test is looking for
357       doesn't match (because of a bug in the compiler), it may match  further
358       away from the use, and mask real bugs away.
359
360       In  those  cases, to enforce the order, use a non-DAG directive between
361       DAG-blocks.
362
363       A CHECK-DAG: directive skips matches that overlap the  matches  of  any
364       preceding CHECK-DAG: directives in the same CHECK-DAG: block.  Not only
365       is this non-overlapping behavior consistent with other directives,  but
366       it's  also  necessary to handle sets of non-unique strings or patterns.
367       For example, the following directives look for  unordered  log  entries
368       for two tasks in a parallel program, such as the OpenMP runtime:
369
370          // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
371          // CHECK-DAG: [[THREAD_ID]]: task_end
372          //
373          // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
374          // CHECK-DAG: [[THREAD_ID]]: task_end
375
376       The  second  pair of directives is guaranteed not to match the same log
377       entries as the first pair even though the patterns  are  identical  and
378       even  if the text of the log entries is identical because the thread ID
379       manages to be reused.
380
381   The CHECK-LABEL: directive
382       Sometimes in a file containing  multiple  tests  divided  into  logical
383       blocks,  one  or  more  CHECK:  directives may inadvertently succeed by
384       matching lines in a later block. While an error will usually eventually
385       be  generated,  the check flagged as causing the error may not actually
386       bear any relationship to the actual source of the problem.
387
388       In  order  to  produce  better  error  messages  in  these  cases,  the
389       "CHECK-LABEL:"  directive  can  be used. It is treated identically to a
390       normal CHECK  directive  except  that  FileCheck  makes  an  additional
391       assumption  that a line matched by the directive cannot also be matched
392       by any other check present in match-filename; this is  intended  to  be
393       used for lines containing labels or other unique identifiers. Conceptu‐
394       ally, the presence of CHECK-LABEL divides the input stream  into  sepa‐
395       rate  blocks,  each  of  which is processed independently, preventing a
396       CHECK: directive in one block matching a line  in  another  block.   If
397       --enable-var-scope is in effect, all local variables are cleared at the
398       beginning of the block.
399
400       For example,
401
402          define %struct.C* @C_ctor_base(%struct.C* %this, i32 %x) {
403          entry:
404          ; CHECK-LABEL: C_ctor_base:
405          ; CHECK: mov [[SAVETHIS:r[0-9]+]], r0
406          ; CHECK: bl A_ctor_base
407          ; CHECK: mov r0, [[SAVETHIS]]
408            %0 = bitcast %struct.C* %this to %struct.A*
409            %call = tail call %struct.A* @A_ctor_base(%struct.A* %0)
410            %1 = bitcast %struct.C* %this to %struct.B*
411            %call2 = tail call %struct.B* @B_ctor_base(%struct.B* %1, i32 %x)
412            ret %struct.C* %this
413          }
414
415          define %struct.D* @D_ctor_base(%struct.D* %this, i32 %x) {
416          entry:
417          ; CHECK-LABEL: D_ctor_base:
418
419       The use of CHECK-LABEL: directives in this case ensures that the  three
420       CHECK:  directives  only  accept lines corresponding to the body of the
421       @C_ctor_base function, even if the patterns match lines found later  in
422       the  file.  Furthermore,  if one of these three CHECK: directives fail,
423       FileCheck will recover by continuing to the next block, allowing multi‐
424       ple test failures to be detected in a single invocation.
425
426       There  is  no  requirement that CHECK-LABEL: directives contain strings
427       that correspond to actual syntactic labels in a source or  output  lan‐
428       guage:  they must simply uniquely match a single line in the file being
429       verified.
430
431       CHECK-LABEL: directives cannot contain variable definitions or uses.
432
433   FileCheck Pattern Matching Syntax
434       All FileCheck directives take a pattern to match.   For  most  uses  of
435       FileCheck,  fixed  string  matching  is perfectly sufficient.  For some
436       things, a more flexible form of matching is desired.  To support  this,
437       FileCheck  allows  you  to  specify  regular  expressions  in  matching
438       strings, surrounded by double braces: {{yourregex}}.  FileCheck  imple‐
439       ments  a  POSIX  regular expression matcher; it supports Extended POSIX
440       regular expressions (ERE). Because we want to use fixed string matching
441       for  a  majority  of what we do, FileCheck has been designed to support
442       mixing and matching fixed string  matching  with  regular  expressions.
443       This allows you to write things like this:
444
445          ; CHECK: movhpd      {{[0-9]+}}(%esp), {{%xmm[0-7]}}
446
447       In this case, any offset from the ESP register will be allowed, and any
448       xmm register will be allowed.
449
450       Because regular expressions are enclosed with double braces,  they  are
451       visually  distinct,  and you don't need to use escape characters within
452       the double braces like you would in C.  In the rare case that you  want
453       to match double braces explicitly from the input, you can use something
454       ugly like {{[{][{]}} as your pattern.
455
456   FileCheck Variables
457       It is often useful to match a pattern and then verify  that  it  occurs
458       again  later  in  the  file.   For codegen tests, this can be useful to
459       allow any register, but verify that that register is used  consistently
460       later.   To do this, FileCheck allows named variables to be defined and
461       substituted into patterns.  Here is a simple example:
462
463          ; CHECK: test5:
464          ; CHECK:    notw     [[REGISTER:%[a-z]+]]
465          ; CHECK:    andw     {{.*}}[[REGISTER]]
466
467       The first check line matches a regex %[a-z]+ and captures it  into  the
468       variable REGISTER.  The second line verifies that whatever is in REGIS‐
469       TER occurs later in the file after an "andw".  FileCheck variable  ref‐
470       erences  are  always  contained  in [[ ]] pairs, and their names can be
471       formed with the regex [a-zA-Z_][a-zA-Z0-9_]*.  If a colon  follows  the
472       name, then it is a definition of the variable; otherwise, it is a use.
473
474       FileCheck  variables can be defined multiple times, and uses always get
475       the latest value.  Variables can also be used later on  the  same  line
476       they were defined on. For example:
477
478          ; CHECK: op [[REG:r[0-9]+]], [[REG]]
479
480       Can  be  useful if you want the operands of op to be the same register,
481       and don't care exactly which register it is.
482
483       If --enable-var-scope is in effect, variables  with  names  that  start
484       with  $  are  considered  to be global. All others variables are local.
485       All local variables get undefined at the beginning of each  CHECK-LABEL
486       block. Global variables are not affected by CHECK-LABEL.  This makes it
487       easier to ensure that individual tests are not  affected  by  variables
488       set in preceding tests.
489
490   FileCheck Expressions
491       Sometimes  there's a need to verify output which refers line numbers of
492       the match file, e.g. when testing compiler  diagnostics.   This  intro‐
493       duces  a  certain  fragility  of  the match file structure, as "CHECK:"
494       lines contain absolute line numbers in the same file, which have to  be
495       updated whenever line numbers change due to text addition or deletion.
496
497       To  support  this case, FileCheck allows using [[@LINE]], [[@LINE+<off‐
498       set>]], [[@LINE-<offset>]] expressions in patterns.  These  expressions
499       expand  to  a  number  of  the line where a pattern is located (with an
500       optional integer offset).
501
502       This way match patterns can be put near the  relevant  test  lines  and
503       include relative line number references, for example:
504
505          // CHECK: test.cpp:[[@LINE+4]]:6: error: expected ';' after top level declarator
506          // CHECK-NEXT: {{^int a}}
507          // CHECK-NEXT: {{^     \^}}
508          // CHECK-NEXT: {{^     ;}}
509          int a
510
511   Matching Newline Characters
512       To  match newline characters in regular expressions the character class
513       [[:space:]] can be used. For example, the following pattern:
514
515          // CHECK: DW_AT_location [DW_FORM_sec_offset] ([[DLOC:0x[0-9a-f]+]]){{[[:space:]].*}}"intd"
516
517       matches output of the form (from llvm-dwarfdump):
518
519          DW_AT_location [DW_FORM_sec_offset]   (0x00000233)
520          DW_AT_name [DW_FORM_strp]  ( .debug_str[0x000000c9] = "intd")
521
522       letting us set  the  FileCheck  variable  DLOC  to  the  desired  value
523       0x00000233, extracted from the line immediately preceding "intd".
524

AUTHOR

526       Maintained by the LLVM Team (https://llvm.org/).
527
529       2003-2019, LLVM Project
530
531
532
533
5348                                 2019-11-13                      FILECHECK(1)
Impressum