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       -version
73              Show the version number of this program.
74

EXIT STATUS

76       If FileCheck verifies that the file matches the expected  contents,  it
77       exits  with  0.  Otherwise, if not, or if an error occurs, it will exit
78       with a non-zero value.
79

TUTORIAL

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

AUTHOR

421       Maintained by The LLVM Team (http://llvm.org/).
422
424       2003-2019, LLVM Project
425
426
427
428
4293.9                               2019-02-01                      FILECHECK(1)
Impressum