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       -help  Print a summary of command line options.
26
27       --check-prefix prefix
28              FileCheck  searches  the contents of match-filename for patterns
29              to  match.   By  default,  these  patterns  are  prefixed   with
30              "CHECK:".  If you'd like to use a different prefix (e.g. because
31              the same input file  is  checking  multiple  different  tool  or
32              options),  the --check-prefix argument allows you to specify one
33              or more prefixes to match.  Multiple  prefixes  are  useful  for
34              tests  which  might  change  for different run options, but most
35              lines remain the same.
36
37       --check-prefixes prefix1,prefix2,...
38              An alias of --check-prefix that allows multiple prefixes  to  be
39              specified as a comma separated list.
40
41       --input-file filename
42              File to check (defaults to stdin).
43
44       --match-full-lines
45              By default, FileCheck allows matches of anywhere on a line. This
46              option will require all positive  matches  to  cover  an  entire
47              line.   Leading  and  trailing  whitespace  is  ignored,  unless
48              --strict-whitespace is also specified. (Note:  negative  matches
49              from CHECK-NOT are not affected by this option!)
50
51              Passing  this option is equivalent to inserting {{^ *}} or {{^}}
52              before, and {{ *$}} or {{$}} after every positive check pattern.
53
54       --strict-whitespace
55              By default, FileCheck canonicalizes input horizontal  whitespace
56              (spaces and tabs) which causes it to ignore these differences (a
57              space will match a tab).  The --strict-whitespace argument  dis‐
58              ables  this behavior. End-of-line sequences are canonicalized to
59              UNIX-style \n in all modes.
60
61       --implicit-check-not check-pattern
62              Adds implicit negative checks for the specified patterns between
63              positive  checks. The option allows writing stricter tests with‐
64              out stuffing them with CHECK-NOTs.
65
66              For example, "--implicit-check-not warning:" can be useful  when
67              testing diagnostic messages from tools that don't have an option
68              similar to clang -verify. With this option FileCheck will verify
69              that  input  does not contain warnings not covered by any CHECK:
70              patterns.
71
72       --enable-var-scope
73              Enables scope for regex variables.
74
75              Variables with names that start with $ are considered global and
76              remain set throughout the file.
77
78              All   other  variables  get  undefined  after  each  encountered
79              CHECK-LABEL.
80
81       -version
82              Show the version number of this program.
83

EXIT STATUS

85       If FileCheck verifies that the file matches the expected  contents,  it
86       exits  with  0.  Otherwise, if not, or if an error occurs, it will exit
87       with a non-zero value.
88

TUTORIAL

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

AUTHOR

440       Maintained by The LLVM Team (http://llvm.org/).
441
443       2003-2019, LLVM Project
444
445
446
447
4485                                 2019-02-01                      FILECHECK(1)
Impressum