<div dir="ltr"><div>Thanks, I had considered using the CHECK-NOT approach. That would work in most cases, I believe, but I'm always nervous to use it because CHECK-NOTs can start failing to check the right thing if output changes. For example, George Rimar recently made changes that turned some list-like structs into dictionaries (using curly brackets instead of square brackets) in the readobj output, which could theoretically have affected the '}' style.</div><div><br></div><div>However, the implicit-check-not approach probably works for many cases. Thanks.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 6 Nov 2019 at 15:49, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I'd usually write this sort of test (& there are many in the DWARF emission tests):<br><br><div><font face="monospace"><br># CHECK:      Name: foo</font></div><div><span style="font-family:monospace"># CHECK-NOT: }</span></div><div><span style="font-family:monospace"># CHECK: Section: .foo (1)<br><br>Or, if you're checking every section, you could use a </span><span style="color:rgb(0,0,0);font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">--implicit-check-not=Symbol or similar.</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 6, 2019 at 4:18 AM James Henderson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"> <div>Hi all,</div><div><br></div><div>Many of our lit tests use FileCheck and a tool like llvm-readobj to check properties of a section header/symbol/etc. A typical (pseudoised for brevity) output to match against might be something like the following:</div><div><br></div><div><span style="font-family:monospace">Symbols [</span></div><div><span style="font-family:monospace">  Symbol {</span></div><div><span style="font-family:monospace">    Name: foo</span></div><div><span style="font-family:monospace">    Value: 0</span></div><div><span style="font-family:monospace">    Type: Function</span></div><div><span style="font-family:monospace">    Section: .foo (1)<br></span></div><div><span style="font-family:monospace">  }</span></div><div><span style="font-family:monospace">  Symbol {</span></div><div><span style="font-family:monospace">    Name: bar</span></div><div><span style="font-family:monospace">    Value: 1</span></div><div><span style="font-family:monospace">    Type: Object</span></div><div><span style="font-family:monospace">    Section: .foo (1)<br></span></div><div><span style="font-family:monospace">  }<br></span></div><div><span style="font-family:monospace">]</span></div><div><br></div><div>and your lit test might want to check the properties of the foo symbol like so:</div><div><br></div><div><font face="monospace"># CHECK:      Name: foo</font></div><div><span style="font-family:monospace"># CHECK-NEXT: Value: 0</span></div><div><span style="font-family:monospace"># CHECK-NEXT: Type: Function</span></div><div><span style="font-family:monospace"># CHECK-NEXT: Section: .foo
 (1)

</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif">This is fine. But what if you only care about the section of a symbol, and not the value or type etc? You could do the following:</font></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif"><br></font></span></div><div><span style="font-family:monospace"># CHECK: Name: foo</span></div><div><span style="font-family:monospace"># CHECK: Section: .foo (1)<br></span></div><div><br></div><div>Hopefully some of you will already notice the problem with this approach: if foo was in, say, the .baz section, the test will spuriously pass, because the Section line will match the Section line for .bar. One alternative to this is to explicitly match each field in between, using CHECK-NEXT:</div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"># CHECK:      Name: foo</span></div><div><span style="font-family:monospace"># CHECK-NEXT: Value:</span></div><div><span style="font-family:monospace"># CHECK-NEXT: Type:</span></div><div><span style="font-family:monospace"># CHECK-NEXT: Section: .foo
 (1)

</span></div><div><br></div><div>This works, but somewhat hides what is really being tested by adding extra noise to the checks. In reality, there are actually other fields too that need to be listed, meaning the "interesting" parts of the test are even more hidden.</div><div><br></div><div>I recently started using yet another approach:</div><div><br></div><div><span style="font-family:monospace"># CHECK: Name: foo</span></div><div><span style="font-family:monospace"># CHECK: Section:</span></div><div><span style="font-family:monospace"># CHECK-SAME:     .foo (1)<br></span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:arial,sans-serif">This works because the Section: matched will be the first one found, i.e. the one belonging to foo, and then .foo will be looked for on the same line. However, I noticed today that this pattern has its own problem, namely that there could be something between the Section tag and .foo. In other words, the above pattern would match "Section: .bar.foo". A couple of solutions to this are:</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"># CHECK: Section:</span></div><div><span style="font-family:monospace"># CHECK-NOT: {{[:graph:]}}</span></div><div><span style="font-family:monospace"># CHECK-SAME: .foo (1)</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"># CHECK: Section:</span></div><div><span style="font-family:monospace"># CHECK-SAME: {{^}} .foo (1)<br></span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif">The first one ensures that there's no non-whitespace between the end of "Section:" and the start of ".foo (1)". The second ensures that the start of the CHECK-SAME match is the "start of line", and since the first half of the line has already been consumed, it means " .foo (1)" must immediately follow "Section:". However, the first is even less readable than the current CHECK-SAME approach, whilst the second is somewhat confusing if you don't realise that FileCheck effectively consumes the things it has matched already, so that they effectively don't exist any more.<br></font></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif"><br></font></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif">Does anybody have any other suggestions/thoughts/comments? One idea I had was for a new directive something like "CHECK-IMMEDIATE" which is implicitly the same as the final approach I suggested above, but maybe adding a new directive to achieve this isn't the right approach?</font></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif"><br></font></span></div><div><span style="font-family:monospace"><font face="arial,sans-serif">James<br></font></span></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>