FILECHECK(1)
๐ FileCheck ยท FILECHECK(1) ยท LLVM โจ
๐ NAME ๐
FileCheck is a flexible pattern matching file verifier ๐
๐ง SYNOPSIS ๐ง
FileCheck match-filename [--check-prefix=XXX] [--strict-whitespace]
๐ธ DESCRIPTION ๐ธ
Okay so FileCheck reads two files: one comes in through standard input, and the other is the one you name on the command line ๐. It uses one of them to verify the other, and ngl that is main character energy ๐. This is especially clutch for the testsuite, which wants to check that the output of some tool (e.g. llc) contains the expected info, like a movsd from esp or whatever is interesting ๐
โจ. It's kinda like grep, but it's built for matching a bunch of different inputs inside one file, in a specific order ๐ซถ.
The match-filename file is the one that holds the patterns to match ๐ฆ. The file to verify gets read from stdin unless you use the --input-file option ๐.
๐ OPTIONS ๐
Okay, bestie, options get parsed from the environment variable FILECHECK_OPTS and from the command line, so you've got two places to slip them in ๐.
-helpโ prints a summary of the command line options ๐--check-prefix prefixโ by default, FileCheck goes hunting through match-filename for patterns that start withCHECK:๐. If you want a different prefix (say, the same input file is checking multiple different tools or options), this argument lets you pick one or more prefixes, written without the trailing:๐. Multiple prefixes are super useful for tests that change between run options but where most lines stay the same ๐.
FileCheck does not allow duplicate prefixes, even if one is a check prefix and the other is a comment prefix (see --comment-prefixes below) ๐.
--check-prefixes prefix1,prefix2,...โ an alias of--check-prefixthat lets you pass multiple prefixes as a comma separated list ๐ง.--comment-prefixes prefix1,prefix2,...โ by default, FileCheck ignores any check prefix in match-filename if it's preceded on the same line byCOM:orRUN:๐ โโ๏ธ. Check out the section The "COM:" directive for the usage details ๐.
You can override these default comment prefixes with --comment-prefixes if they don't fit your testing environment. However, that's not recommended in LLVM's LIT-based test suites, since those are way easier to maintain when everyone follows one consistent comment style ๐ญ. If the defaults feel wrong, consider proposing a change to the default comment prefixes instead ๐.
--allow-unused-prefixesโ this one controls what happens when you use more than one prefix (via--check-prefixor--check-prefixes) and some of those prefixes are missing from the test file ๐ง. If it's true, that's allowed. If it's false, FileCheck reports an error and lists the missing prefixes ๐จ.
It's currently, temporarily, true by default, and it'll be switched to false later on โณ.
--input-file filenameโ the file to check (defaults to stdin) ๐ฅ.--match-full-linesโ by default, FileCheck is chill and allows matches anywhere on a line ๐ค๏ธ. This option levels up and requires every positive match to cover an entire line ๐ . Leading and trailing whitespace gets ignored, unless--strict-whitespaceis also specified ๐ซง.
Heads up: negative matches from CHECK-NOT are not affected by this option!
Passing this option is equivalent to inserting {{^ *}} or {{^}} before, and {{ *$}} or {{$}} after, every positive check pattern ๐ง .
--strict-whitespaceโ by default, FileCheck canonicalizes horizontal whitespace in the input (spaces and tabs), so it ignores those differences and a space will match a tab ๐ช. This option turns that behavior off โ. End-of-line sequences get canonicalized to UNIX-style\nin all modes ๐ง.--ignore-caseโ by default, matching is case-sensitive ๐ . This option switches FileCheck over to case-insensitive matching ๐ซ .--implicit-check-not check-patternโ adds implicit negative checks for the specified patterns between positive checks โจ. This lets you write stricter tests without stuffing them full ofCHECK-NOTs ๐งน.
For example, --implicit-check-not warning: is super handy when you're testing diagnostic messages from tools that don't have an option similar to clang -verify ๐. With this option, FileCheck verifies that the input doesn't contain any warnings that aren't covered by a CHECK: pattern ๐ซโ ๏ธ.
(more to come, bestie ๐๐ )
define <4 x i32> @pinsrd_1(i32 %s, <4 x i32> %tmp) nounwind {
%tmp1 = insertelement <4 x i32>; %tmp, i32 %s, i32 1
ret <4 x i32> %tmp1
; X32: pinsrd_1:
; X32: pinsrd $1, 4(%esp), %xmm0
; X64: pinsrd_1:
; X64: pinsrd $1, %edi, %xmm0
}
Ngl this one is testing that we get the expected code gen with both 32-bit and 64-bit code gen ๐ซถ Main character codegen, no notes ๐
๐ The โCOM:โ directive ๐
Sometimes you wanna turn off a FileCheck directive without deleting it entirely, or you wanna write comments that mention a directive by name ๐ Thatโs where COM: comes in, and it makes this so easy. For example, you might have:
; X32: pinsrd_1:
; X32: pinsrd $1, 4(%esp), %xmm0
; COM: FIXME: X64 isn't working correctly yet for this part of codegen, but
; COM: X64 will have something similar to X32:
; COM:
; COM: X64: pinsrd_1:
; COM: X64: pinsrd $1, %edi, %xmm0
Without COM:, youโd have to do some combo of rewording and directive syntax mangling so FileCheck doesnโt recognize the commented X32: and X64: occurrences above as directives ๐ญ Also, FileCheck diagnostics have been proposed that might complain about those X64 occurrences above that donโt have the trailing :, because they look like directive typos. Dodging all of that is so tedious for a test author, and directive syntax mangling can make the purpose of test code unclear. COM: avoids all these problems ๐
A few important usage notes:
COM:within another directiveโs pattern does not comment out the remainder of the pattern. For example:
; X32: pinsrd $1, 4(%esp), %xmm0 COM: This is part of the X32 pattern!
If you need to temporarily comment out part of a directiveโs pattern, move it to another line. The reason is that FileCheck parses COM: in the same manner as any other directive: only the first directive on the line is recognized as a directive.
- For the sake of LIT, FileCheck treats
RUN:just likeCOM:. If this is not suitable for your test environment, see--comment-prefixes. - FileCheck does not recognize
COM,RUN, or any user-defined comment prefix as a comment directive if itโs combined with one of the usual check directive suffixes, such as-NEXT:or-NOT:, discussed below. FileCheck treats such a combination as plain text instead. If it needs to act as a comment directive for your test environment, define it as such with--comment-prefixes.
๐ฆ The โCHECK-NEXT:โ directive ๐ฆ
Sometimes you want to match lines and verify that the matches happen on exactly consecutive lines, with no other lines in between. For that, use CHECK: and CHECK-NEXT: together. If youโve got a custom check prefix, just use <PREFIX>-NEXT:. Something like this works exactly how youโd expect:
define void @t2(<2 x double>* %r, <2 x double>* %A, double %B) {
%tmp3 = load <2 x double>* %A, align 16
%tmp7 = insertelement <2 x double> undef, double %B, i32 0
%tmp9 = shufflevector <2 x double> %tmp3,
<2 x double> %tmp7,
<2 x i32> < i32 0, i32 2 >
store <2 x double> %tmp9, <2 x double>* %r, align 16
ret void
; CHECK: t2:
; CHECK: movl 8(%esp), %eax
; CHECK-NEXT: movapd (%eax), %xmm0
; CHECK-NEXT: movhpd 12(%esp), %xmm0
; CHECK-NEXT: movl 4(%esp), %eax
; CHECK-NEXT: movapd %xmm0, (%eax)
; CHECK-NEXT: ret
}
CHECK-NEXT: directives reject the input unless there is exactly one newline between it and the previous directive. A CHECK-NEXT: cannot be the first directive in a file.
๐ The โCHECK-SAME:โ directive ๐
Sometimes you want matches to happen on the same line as the previous match, and you want that verified. Use CHECK: and CHECK-SAME: for this. If youโve got a custom check prefix, just use <PREFIX>-SAME:.
CHECK-SAME: is especially powerful in conjunction with CHECK-NOT: (described below).
For example, the following works like youโd expect:
!0 = !DILocation(line: 5, scope: !1, inlinedAt: !2)
; CHECK: !DILocation(line: 5,
; CHECK-NOT: column:
; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
CHECK-SAME: directives reject the input if there are any newlines between it and the previous directive.
CHECK-SAME: is also super useful for avoiding writing matchers for irrelevant fields. Say youโre writing a test that parses a tool generating output like this:
Name: foo
Field1: ...
Field2: ...
Field3: ...
Value: 1
Name: bar
Field1: ...
Field2: ...
Field3: ...
Value: 2
Name: baz
Field1: ...
Field2: ...
Field3: ...
Value: 1
To write a test that verifies foo has the value 1, you might first write this:
CHECK: Name: foo
CHECK: Value: 1{{$}}
Lowkey a bad test ๐ญ If the value for foo changes, the test would still pass, because the CHECK: Value: 1 line would match the value from baz. You could fix that by adding CHECK-NEXT matchers for every FieldN: line, but thatโs verbose and would need updating whenever Field4 is added. A more succinct way to write the test, using the CHECK-SAME: matcher, would be as follows:
CHECK: Name: foo
CHECK: Value:
CHECK-SAME: {{ 1$}}
This verifies that the next time โValue:โ appears in the output, it has the value 1 โจ
Note: a CHECK-SAME: cannot be the first directive in a file.
๐ธ The โCHECK-EMPTY:โ directive ๐ธ
If you need to check that the next line has nothing on it, not even whitespace, use the CHECK-EMPTY: directive.
declare void @foo()
declare void @bar()
; CHECK: foo
; CHECK-EMPTY:
; CHECK-NEXT: bar
Just like CHECK-NEXT:, this directive will fail if there is more than one newline before it finds the next blank line, and it cannot be the first directive in a file.
๐ซถ The โCHECK-NOT:โ directive ๐ซถ
The CHECK-NOT: directive is used to verify that a string doesnโt occur between two matches (or before the first match, or after the last match). For example, to verify that a load is removed by a transformation, a test like this can be used:
define i8 @coerce_offset0(i32 %V, i32* %P) {
store i32 %V, i32* %P
%P2 = bitcast i32* %P to i8*
%P3 = getelementptr i8* %P2, i32 2
%A = load i8* %P3
ret i8 %A
; CHECK: @coerce_offset0
; CHECK-NOT: load
; CHECK: ret i8
}
๐ง The โCHECK-COUNT:โ directive ๐ง
If you need to match multiple lines with the same pattern over and over, you can repeat a plain CHECK: as many times as needed. If that looks too boring, you can instead use a counted check, CHECK-COUNT-<num>:, where <num> is a positive decimal number. It will match the pattern exactly <num> times, no more and no less. If you specified a custom check prefix, just use <PREFIX>-COUNT-<num>: for the same effect. Here is a simple example:
Loop at depth 1
Loop at depth 1
Loop at depth 1
Loop at depth 1
Loop at depth 2
Loop at depth 3
; CHECK-COUNT-6: Loop at depth {{[0-9]+}}
; CHECK-NOT: Loop at depth {{[0-9]+}}
๐ The โCHECK-DAG:โ directive ๐
If itโs necessary to match strings that donโt occur in a strictly sequential order, CHECK-DAG: can be used to verify them between two matches (or before the first match, or after the last match). For example, clang emits vtable globals in reverse order. Using CHECK-DAG:, we can keep the checks in the natural order:
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
struct Foo { virtual void method(); };
Foo f; // emit vtable
// CHECK-DAG: @_ZTV3Foo =
struct Bar { virtual void method(); };
Bar b;
// CHECK-DAG: @_ZTV3Bar =
CHECK-NOT: directives could be mixed with CHECK-DAG: directives to exclude strings between the surrounding CHECK-DAG: directives. As a result, the surrounding CHECK-DAG: directives cannot be reordered, i.e. all occurrences matching CHECK-DAG: before CHECK-NOT: must not fall behind occurrences matching CHECK-DAG: after CHECK-NOT:. For example,
; CHECK-DAG: BEFORE
; CHECK-NOT: NOT
; CHECK-DAG: AFTER
This case will reject input strings where BEFORE occurs after AFTER.
With captured variables, CHECK-DAG: is able to match valid topological orderings of a DAG with edges from the definition of a variable to its use. Itโs useful, e.g., when your test cases need to match different output sequences from the instruction scheduler. For example,
; CHECK-DAG: add [[REG1:r[0-9]+]], r1, r2
; CHECK-DAG: add [[REG2:r[0-9]+]], r3, r4
; CHECK: mul r5, [[REG1]], [[REG2]]
In this case, any order of those two add instructions will be allowed.
If you are defining and using variables in the same CHECK-DAG: block, be aware that the definition rule can match after its use.
So, for instance, the code below will pass:
; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0]
; CHECK-DAG: vmov.32 [[REG2]][1]
vmov.32 d0[1]
vmov.32 d0[0]
While this other code will not:
; CHECK-DAG: vmov.32 [[REG2:d[0-9]+]][0]
; CHECK-DAG: vmov.32 [[REG2]][1]
vmov.32 d1[1]
vmov.32 d0[0]
While this can be very useful, itโs also dangerous. In the case of register sequences, you must have a strong order (read before write, copy before use, etc). If the definition your test is looking for doesnโt match (because of a bug in the compiler), it may match further away from the use, and mask real bugs away ๐
In those cases, to enforce the order, use a non-DAG directive between DAG-blocks.
A CHECK-DAG: directive skips matches that overlap the matches of any preceding CHECK-DAG: directives in the same CHECK-DAG: block. Not only is this non-overlapping behavior consistent with other directives, but itโs also necessary to handle sets of non-unique strings or patterns. For example, the following directives look for unordered log entries for two tasks in a parallel program, such as the OpenMP runtime:
// CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
// CHECK-DAG: [[THREAD_ID]]: task_end
//
// CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
// CHECK-DAG: [[THREAD_ID]]: task_end
okay so the second pair of directives is guaranteed not to match the same log entries as the first pair ๐ซถ even if the patterns are identical, and even if the log text is identical, because the thread ID can totally manage to get reused ๐งตโจ
โจ The โCHECK-LABEL:โ directive โจ
Sometimes in a file with multiple tests split into logical blocks, one or more CHECK: directives can accidentally pass by matching lines in a later block ๐ญ An error will usually show up eventually, but the check that gets blamed may have zero connection to the real problem. Not it! ๐
โโ๏ธ
So to get better error messages in these situations, the โCHECK-LABEL:โ directive is your bestie ๐ It works exactly like a normal CHECK: directive, except FileCheck assumes that a line matched by it can't also be matched by any other check in match-filename. It's meant for lines with labels or other unique identifiers ๐ Conceptually, CHECK-LABEL: splits the input stream into separate blocks, and each block gets processed on its own, so a CHECK: in one block can't grab a line from another block. Main character energy ๐ If --enable-var-scope is in effect, all local variables get cleared at the beginning of the block.
For example,
define %struct.C* @C_ctor_base(%struct.C* %this, i32 %x) {
entry:
; CHECK-LABEL: C_ctor_base:
; CHECK: mov [[SAVETHIS:r[0-9]+]], r0
; CHECK: bl A_ctor_base
; CHECK: mov r0, [[SAVETHIS]]
%0 = bitcast %struct.C* %this to %struct.A*
%call = tail call %struct.A* @A_ctor_base(%struct.A* %0)
%1 = bitcast %struct.C* %this to %struct.B*
%call2 = tail call %struct.B* @B_ctor_base(%struct.B* %1, i32 %x)
ret %struct.C* %this
}
define %struct.D* @D_ctor_base(%struct.D* %this, i32 %x) {
entry:
; CHECK-LABEL: D_ctor_base:
So in this case, the CHECK-LABEL: directives make sure the three CHECK: directives only accept lines from the body of the @C_ctor_base function, even if their patterns match lines way down later in the file ๐ And if one of those three CHECK: directives fails, FileCheck just recovers and moves on to the next block, so you can catch multiple test failures in one invocation. Iconic behaviour, honestly ๐ฅ
There is no rule saying CHECK-LABEL: strings have to match real syntactic labels in a source or output language ๐ง They just have to uniquely match a single line in the file being verified. Lowkey freeing ๐ฆ
CHECK-LABEL: directives cannot contain variable definitions or uses ๐ซ
๐ Directive modifiers ๐
You can append a directive modifier to a directive by following the directive with {<modifier>}, and the only supported value for <modifier> is LITERAL ๐
The LITERAL modifier gives you a literal match. The directive stops recognising any syntax for regex matching, variable capture, or substitutions. This is so useful when the text you're matching would need excessive escaping otherwise ๐ฉ For example, the following lines do literal matches instead of treating them as regular expressions:
Input: [[[10, 20]], [[30, 40]]]
Output %r10: [[10, 20]]
Output %r10: [[30, 40]]
; CHECK{LITERAL}: [[[10, 20]], [[30, 40]]]
; CHECK-DAG{LITERAL}: [[30, 40]]
; CHECK-DAG{LITERAL}: [[10, 20]]
๐ฆ FileCheck Regex Matching Syntax ๐ฆ
Every FileCheck directive takes a pattern to match ๐ธ For most uses, fixed string matching is perfectly sufficient, but sometimes you need something more flexible. That's where regex comes in. You can write regular expressions inside double braces, like {{yourregex}}, and FileCheck implements a POSIX regular expression matcher that supports Extended POSIX regular expressions (ERE). Since most of what we do is fixed string matching, FileCheck is built to mix and match fixed strings with regexes, so you can write stuff like this:
; CHECK: movhpd {{[0-9]+}}(%esp), {{%xmm[0-7]}}
In this case, any offset from the ESP register is allowed, and any xmm register is allowed โจ
Because regexes are wrapped in double braces, they look visually distinct, and you don't need to escape anything inside them the way you would in C ๐ In the rare case that you want to match double braces literally from the input, you can use something ugly like {{[}][}]}} as your pattern ๐ Or, if you're using the repetition count syntax, like [[:xdigit:]]{8} to match exactly 8 hex digits, you'll need to add parentheses like this: {{([[:xdigit:]]{8})}}, so it doesn't get confused with FileCheck's closing double-brace ๐ซ
๐ FileCheck String Substitution Blocks ๐
Sometimes you want to match a pattern and then check that it shows up again later in the file ๐ For codegen tests, this lets you accept any register, but verify that the same register gets used consistently afterwards. FileCheck does this with string substitution blocks, which let you define string variables and substitute them into patterns. Here's a simple example:
; CHECK: test5:
; CHECK: notw [[REGISTER:%[a-z]+]]
; CHECK: andw {{.*}}[[REGISTER]]
The first check line matches the regex %[a-z]+ and captures it into the string variable REGISTER. The second line checks that whatever's in REGISTER shows up later in the file after an โandwโ ๐ง String substitution blocks are always wrapped in [[ ]] pairs, and variable names can be formed with the regex [a-zA-Z_][a-zA-Z0-9_]*. If a colon follows the name, it's a definition of the variable. Otherwise, it's a substitution ๐ฏ
Variables can be defined multiple times, and substitutions always grab the latest value ๐ You can also substitute a variable later on the same line where it was defined. For example:
; CHECK: op [[REG:r[0-9]+]], [[REG]]
This is handy if you want the operands of op to be the same register and don't care exactly which one it is ๐ง
If --enable-var-scope is in effect, variables whose names start with $ count as global. Every other variable is local. All local variables get undefined at the beginning of each CHECK-LABEL block, but global variables aren't affected by CHECK-LABEL at all. This makes it way easier to make sure individual tests aren't influenced by variables set in earlier tests ๐ซถ
๐ข FileCheck Numeric Substitution Blocks ๐ข
FileCheck also supports numeric substitution blocks, which let you define numeric variables and check for numeric values that satisfy a numeric expression constraint built from those variables โจ This lets a CHECK: directive verify a numeric relationship between two numbers, like making sure consecutive registers get used ๐ค
The syntax for capturing a numeric value is [[#%<fmtspec>,<NUMVAR>:]], where:
%<fmtspec>,โ an optional format specifier that says what number format to match and the minimum number of digits to expect.<NUMVAR>:โ an optional definition of the variable<NUMVAR>from the captured value.
The syntax of <fmtspec> is #.<precision><conversion specifier>, where:
#โ an optional flag for hex values (see<conversion specifier>below) that requires the matched value to be prefixed by0x..<precision>โ an optional printf-style precision specifier.<precision>is the minimum number of digits the matched value must have, with leading zeros if needed.<conversion specifier>โ an optional scanf-style conversion specifier that says what number format to match (e.g. hex number). The currently accepted format specifiers are%u,%d,%xand%X. If it's absent, the format specifier defaults to%u.
For example:
; CHECK: mov r[[#REG:]], 0x[[#%.8X,ADDR:]]
would match mov r5, 0x0000FEFE and set REG to the value 5 and ADDR to the value 0xFEFE. Note that because of the precision, it would fail to match mov r5, 0xFEFE ๐ญ
Since defining a numeric variable is optional, you can also just check that a numeric value is present in a given format ๐ This is useful when the actual value doesn't matter, for instance:
; CHECK-NOT: mov r0, r[[#]]
to check that a value is synthesized rather than moved around ๐งช
The syntax of a numeric substitution is [[#%<fmtspec>, <constraint> <expr>]], where:
<fmtspec>โ the same format specifier you'd use when defining a variable, but here it tells FileCheck how to match a numeric expression value. If it's absent, both parts of the format specifier are inferred from the matching format of the numeric variable(s) used by the expression constraint, if there are any. If no numeric variable is used, it defaults to%u, meaning the value should be unsigned with no leading zeros. If several numeric variables have conflicting format specifiers, the conversion specifier becomes mandatory, but the precision specifier stays optional.<constraint>โ the constraint describing how the value to match has to relate to the value of the numeric expression. The only currently accepted constraint is==for an exact match, and it's the default if<constraint>isn't provided. No matching constraint should be specified when<expr>is empty.<expr>โ an expression, which is recursively defined as:- a numeric operand, or
- an expression followed by an operator and a numeric operand.
A numeric operand is a previously defined numeric variable, an integer literal, or a function. Spaces are accepted before, after and between any of these elements. Numeric operands have 64-bit precision. Overflow and underflow are rejected. There's no operator precedence, but you can use parentheses to change the evaluation order ๐งฎ
The supported operators are:
+โ Returns the sum of its two operands.-โ Returns the difference of its two operands.
The syntax of a function call is <name>(<arguments>), where:
nameโ a predefined string literal. The accepted values are:addโ Returns the sum of its two operands.divโ Returns the quotient of its two operands.maxโ Returns the largest of its two operands.minโ Returns the smallest of its two operands.mulโ Returns the product of its two operands.
sub: okay bestie, this one gives you the difference between its two operands ๐<arguments>is basically a comma-separated list of expressions ๐ง
For example:
; CHECK: load r[[#REG:]], [r0]
; CHECK: load r[[#REG+1]], [r1]
; CHECK: Loading from 0x[[#%x,ADDR:]]
; CHECK-SAME: to 0x[[#ADDR + 7]]
So the above would match this text ๐ฆ:
load r5, [r0]
load r6, [r1]
Loading from 0xa0463440 to 0xa0463447
but it would NOT match this text ๐:
load r5, [r0]
load r7, [r1]
Loading from 0xa0463440 to 0xa0463443
Why? 7 is not equal to 5 + 1, and a0463443 is not equal to a0463440 + 7. The vibes are just off ๐
Okay so you can also define a numeric variable as the result of a numeric expression โจ. The expression constraint gets checked, and if it passes, the variable is assigned that value. The unified syntax for both checking a numeric expression and capturing its value into a numeric variable is [[#%<fmtspec>,<NUMVAR>: <constraint> <expr>]], with each element described previously. Using variables instead of values makes a testcase so self-describing, it's giving genius ๐:
; CHECK: mov r[[#REG_OFFSET:]], 0x[[#%X,FIELD_OFFSET:12]]
; CHECK-NEXT: load r[[#]], [r[[#REG_BASE:]], r[[#REG_OFFSET]]]
which would match:
mov r4, 0xC
load r6, [r5, r4]
The --enable-var-scope option has the same effect on numeric variables as it does on string variables ๐ธ
๐จ Important note: In its current implementation, an expression cannot use a numeric variable defined earlier in the same CHECK directive.
โจ FileCheck Pseudo Numeric Variables โจ
Sometimes you need to verify output that contains line numbers from the match file, like when you're testing compiler diagnostics ๐. This makes the match file kinda fragile, though, because CHECK: lines contain absolute line numbers in the same file. Those have to get updated whenever line numbers change from text getting added or deleted ๐ญ.
To fix that, FileCheck expressions understand the @LINE pseudo numeric variable. It evaluates to the line number of the CHECK pattern where it's found ๐ง
This way, match patterns can live right next to the relevant test lines and use relative line number references, for example:
// CHECK: test.cpp:[[# @LINE + 4]]:6: error: expected ';' after top level declarator
// CHECK-NEXT: {{^int a}}
// CHECK-NEXT: {{^ \^}}
// CHECK-NEXT: {{^ ;}}
int a
For legacy uses of @LINE as a special string variable, FileCheck also accepts @LINE with string substitution block syntax: [[@LINE]], [[@LINE+<offset>]] and [[@LINE-<offset>]]. Keep the brackets free of spaces, and make sure the offset is an integer ๐
Matching Newline Characters ๐
To match newline characters in regular expressions, use the character class [[:space:]]. For example, this pattern:
// CHECK: DW_AT_location [DW_FORM_sec_offset] ([[DLOC:0x[0-9a-f]+]]){{[[:space:]].*}}"intd"
matches output of the form (from llvm-dwarfdump):
DW_AT_location [DW_FORM_sec_offset] (0x00000233)
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c9] = "intd")
which lets us set the FileCheck variable DLOC to the desired value 0x00000233, pulled from the line immediately preceding โintdโ. Main character energy ๐ฆ
โจ AUTHOR โจ
Maintained by the LLVM Team (https://llvm.org/) ๐ซถ
โจ COPYRIGHT โจ
2003-2025, LLVM Project
And that's a wrap on FILECHECK(1), bestie! ๐ It's from the LLVM Project, dated 2025-05-22. Now go check those patterns and slay the test suite ๐ โจ
๐ฆ where this page comes from
- ubuntu questing: llvm-14 1:14.0.6-20ubuntu3
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms