<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">(Repost, remembering to cc llvm-dev this time)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks Jon!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ve done some grepping for a few of these gotchas in llvm/test and clang/test. Of course this isn’t looking for the check prefixes that are actually used, but CHECK would be by far the most common, so I think we can take it as a non-definitive
proxy for other cases.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Gotcha A (missing colon): This has a fair number of examples in the wild. Usually the colon is just missing, although I’ve seen a few examples that had a semicolon instead of colon, which is an easy typo to make. The real problem here
is coming up with a heuristic that will distinguish “things that are likely a mistake” from “things that are likely just a comment” so that the diagnostic has a reasonably low false-positive rate.<o:p></o:p></p>
<p class="MsoNormal">For example, in the wild I’ve seen `// TEMPORARY CHECK: X` which FileCheck will treat as a real directive. On the other hand we *<b>don’t</b>* want it to look at `// These CHECK lines are here on purpose` and diagnose that as a missing
colon.<o:p></o:p></p>
<p class="MsoNormal">I’ve been poking at this over the past day or so and I now think the most reasonable heuristic is: If the directive is preceded by an alphanumeric (+ whitespace) or an `=` or ‘,’ then it’s likely a comment or a RUN: line that we don’t want
to diagnose. This means we would not diagnose a missing colon in `// TEMPORARY CHECK; X` but that sort of case is extremely rare. We *<b>would</b>* diagnose `// (TEMPORARY) CHECK; X` however.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Another question was whether we should *<b>require</b>* FileCheck directives to be preceded by a punctuation mark of some kind. I think that ought to be its own separate discussion.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Gotcha B (space between the directive and the colon): Some tests have this bug, so it would be worth catching.<o:p></o:p></p>
<p class="MsoNormal">James Henderson observed that legalizing it could help prettify some cases where we’re matching whitespace or the entire line. I don’t think it’s that valuable personally.<o:p></o:p></p>
<p class="MsoNormal">If we implement a reasonable diagnostic heuristic for the missing-colon case (Gotcha A), then we’ll catch this mistake in the same net.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Gotchas C,D (missing hyphen): I found exactly one case in the wild. I’d say the value is debatable.<o:p></o:p></p>
<p class="MsoNormal">(It’s a CHECKNEXT in llvm/test/CodeGen/PowerPC/testCompareslleqsi.ll if someone wants to fix it.)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Gotcha E (underscore instead of hyphen): I found 40 examples across clang/test and llvm/test. I am certain I have caught a few cases in review and pretty sure I’ve had to fix some of these that I typo’d myself. I’d say this is worth
doing.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Multiple suffixes: I believe there are NO multiple-suffix combinations that FileCheck currently supports. The tool should detect any multiple suffix combinations and report them as errors. Currently it looks for a limited set (basically,
-NOT in combination with almost anything else), but it’s easy for someone to infer that if FileCheck doesn’t complain, then it will Do The Right Thing™ with other combinations. We should not be that user-unfriendly; we should complain about all multiple-suffix
combinations.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">--paulr<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Jon Roelofs via llvm-dev<br>
<b>Sent:</b> Friday, April 3, 2020 12:58 PM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [llvm-dev] [RFC] Improving FileCheck<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I'd like to (re)start a discussion on a few gotchas in FileCheck that I've noticed working on various tests in llvm's suites. This begain in a review [1], but I'll try to summarize here so it gets the right audience before decisions are
made on it (so to speak).<br>
<br>
1: <a href="https://reviews.llvm.org/D77227">https://reviews.llvm.org/D77227</a><br>
<br>
The main sticking point is the abundance of checks in FileCheck tests that appear to be checking something, but are in fact silently hiding failures. The biggest class of this bug appears to be CHECK lines that omit the trailing colon, though there are a few
others.<br>
<br>
CHECK: legitimate test<br>
CHECK gotcha A<br>
CHECK : gotcha B<br>
CHECKNEXT: gotcha C<br>
CHECKDAG: gotcha D<br>
CHECK_NOT: gotcha E<br>
CHECK-LABEL-NOT: ??? F<br>
CHECK-SAME-DAG: ??? G<br>
<br>
<br>
Gotcha A<br>
--------<br>
<br>
CHECK gotcha A<br>
<br>
A lot of cases of (A) are benign, but buried in there are cases where we have tests that don't check what they intend to, which are broken when the missing colons are added [2]. Some grep analysis from paulr in [3] found some 178 tests across 72 test files
that seem like likely mistakes, suggesting that having some automated tooling to catch this is probably not a bad idea.<br>
<br>
In the review thread, a couple of issues surfaced with simply matching on `${CHECKNAME}\b`, making that less attractive as a remedy:<br>
<br>
A1) There are quite a lot of RUN: lines that have CHECK names on them from their --check-prefix/--check-prefixes arguments, and we don't want tooling to match on those. This could be addressed with a script that quotes them all, but that would mean touching
pretty much every test file, which is less than ideal.<br>
<br>
A2) There are a few RUN lines with missing colons, though those seem infrequent enough to not worry about [5].<br>
<br>
A3) There are quite a lot of mentions of CHECK names in comments that are clearly not meant to be tests [6]. Any solution to this, as far as I can tell, will likely need to reword many of those.<br>
<br>
A4) We need some way to comment out CHECK lines that conveys intent better than removing the colon. This appears to be intentional in some testcases, but unintentional in the vast majority of them.<br>
<br>
To address (A1), a number of rules were proposed in [1], the best of which seems to be that we look for lines matching `[#/;*!]\s*CHECK[ \t]`, and emit a diagnostic of some form to help correct it. This gave a pretty good false positive rate of 25% on the 186
tests it "broke" [7].<br>
<br>
An open question here from jdenny is whether it makes sense to require all checks to follow that pattern (with the colon, of course) to make things less user-hostile [8]:
<br>
<br>
> Consider this example that has a well formed directive that doesn't follow the rule:<br>
> <br>
> // FIXME(201806L) CHECK: assert: 0<br>
> Approach A (from a previous comment): FileCheck executes the directive. If the user later accidentally removes the :, FileCheck won't execute the directive and won't diagnose the error unless the user is wiling to endure false positives by opting into the
more verbose mode Paul suggested.<br>
> <br>
> Approach B (from that some comment): FileCheck ignores the directive. That just makes things worse because the above otherwise well formed directive is then an undiagnosed malformed directive (unless the user opts into a more verbose mode).<br>
> <br>
> Approach C (new proposal): FileCheck reports the directive as an error (in any mode). The more verbose mode is still needed to catch the case that the : is missing here, but at least users are guaranteed to get a slap when they write them with :<br>
2: llvm/test/Transforms/InstCombine/phi-preserve-ir-flags.ll<br>
3: <a href="https://reviews.llvm.org/D77227#1955596">https://reviews.llvm.org/D77227#1955596</a><br>
4: <a href="https://github.com/llvm/llvm-project/blob/56decd982dc03a74d1796d9d4dbd7d9e0cea98dc/llvm/lib/Support/FileCheck.cpp#L1141">
https://github.com/llvm/llvm-project/blob/56decd982dc03a74d1796d9d4dbd7d9e0cea98dc/llvm/lib/Support/FileCheck.cpp#L1141</a><br>
5: llvm/test/CodeGen/AArch64/speculation-hardening.ll<br>
6: llvm/test/MC/ARM/dwarf-asm-multiple-sections.s:88<br>
7: <a href="https://reviews.llvm.org/differential/diff/254562">https://reviews.llvm.org/differential/diff/254562</a><br>
8: <a href="https://reviews.llvm.org/D77227#1958228">https://reviews.llvm.org/D77227#1958228</a><br>
<br>
<br>
Gotcha B<br>
--------<br>
<br>
CHECK : gotcha B<br>
<br>
This pattern is a variant of (A) that also disables perfectly good tests, but in a way that isn't obvious that it doesn't work. jhenderson brings up some good points [9] in favor of extending FileCheck to make FileCheck do what the user intended here. Luckily,
that doesn't seem to conflict with the rules proposed in (A).<br>
<br>
9: <a href="https://reviews.llvm.org/D77227#1959041">https://reviews.llvm.org/D77227#1959041</a><br>
<br>
<br>
Gotchas C, D, E<br>
---------------<br>
<br>
I believe these can be handled pretty simply in FileCheck itself, but I have not spent much time trying to estimate how many tests are affected by this class of bug.<br>
<br>
<br>
??? F, G<br>
--------<br>
<br>
There are a number of check suffix combinations that are not explicitly supported (in the docs), but appear (maybe) useful. For these, there is some precedent on mitigating them within FileCheck itself [4], though the combinatorial explosion warrants being
careful about how we go about detecting them (if at all).<br>
<br>
<br>
-- <br>
Jon Roelofs<br>
<a href="mailto:jroelofs@jroelofs.com">jroelofs@jroelofs.com</a><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>