<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 17, 2020 at 2:52 PM Joel E. Denny <<a href="mailto:jdenny.ornl@gmail.com">jdenny.ornl@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"><div dir="ltr">Hi Nathan,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 17, 2020 at 12:23 PM Nathan James via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-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">Hello,<br>
<br>
I was wondering about extending FileCheck to enable creating line<br>
anchors. These are numeric variables that hold the value of the line<br>
number that where they were defined.<br></blockquote><div><br></div><div>I think something like this could be useful. However, I think it would be more useful to have a general directive for defining FileCheck variables inline without trying to capture from input. For example:<br></div><div><br></div><div>```<br></div><div>#define BAD_FUNCTION() badFunction() // CHECK-DEFINE: [[#BAD_FUNC:@LINE]]<br>
// Further down in the file<br>
BAD_FUNCTION();<br>
CHECK-NOTES: [[@LINE-1]]:3: warning: called a bad function<br>
CHECK-NOTES :[[#BAD_FUNC]]:3: note: expanded from macro 'BAD_FUNCTION'</div><div>```</div><div><br></div><div>The exact syntax is debatable.</div><div><br></div><div>I think this form is more useful because it can also define strings or numerics (or maybe even patterns) to be reused in multiple FileCheck directives across multiple FileCheck calls from different RUN lines. Currently, you either have to capture such a variable from the input or specify it with -D on every FileCheck call that needs it.<br></div><div><br></div><div>James Henderson: Weren't you working on something like this?</div><div><br></div><div>Thanks.<br></div><div><br></div><div>Joel<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The motivation for this comes from test cases using clang-based<br>
diagnostics which often include notes attached to source locations in<br>
different parts of the file. In order to test for the correct location<br>
of the note, the line number has to be written explicitly or as an,<br>
often large, offset to the current line. This harms both readability<br>
and maintainability. Using this new system one could append a line of<br>
interest with an anchor-comment and refer back to it inside FileCheck.<br></blockquote></div></div></blockquote><div><br></div><div><div>Also, just in case you weren't aware, there is a Clang facility for checking its own diagnostics:<br></div><div><br></div><div><a href="http://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details">http://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details</a></div><div><br></div><div>You'd put a directive for each diagnostic on or near the line it cites.<br></div><div><br></div><div></div><div>Joel<br></div><div> <br></div></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 class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I have created a basic patch that implements this here <br>
<a href="https://reviews.llvm.org/D84037" rel="noreferrer" target="_blank">https://reviews.llvm.org/D84037</a> but it definitely needs a few looks<br>
over by people who are more clued up on the internal of FileCheck.<br>
<br>
The current syntax, based off this patch, is as follows:<br>
- Added a command line option called `anchor-prefix` which is a<br>
comma-seperated list of prefixes to be used when declaring anchors.<br>
This is defaulted to `LINE-ANCHOR`<br>
- To declare a anchor in the test file use<br>
`LINE-ANCHOR: ANCHOR_NAME`<br>
note: If you specify a different anchor-prefix using the command<br>
line, use that name instead of `LINE-ANCHOR`<br>
ANCHOR_NAME Follows the rules all other variable names aside from<br>
the fact it can't start with '$'.<br>
- When referring to an anchor in a check use the same numeric<br>
variable syntax that FileCheck already supports:<br>
`CHECK: [[#ANCHOR_NAME]][[#ANCHOR_NAME+1]]`<br>
<br>
Here is a brief (contrived) example of the usage of this:<br>
```<br>
#define BAD_FUNCTION() badFunction() // LINE-ANCHOR: BAD_FUNC<br>
// Further down in the file<br>
BAD_FUNCTION();<br>
CHECK-NOTES: [[@LINE-1]]:3: warning: called a bad function<br>
CHECK-NOTES :[[#BAD-FUNC]]:3: note: expanded from macro 'BAD_FUNCTION'<br>
```<br>
<br>
Regards,<br>
Nathan James<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>
</blockquote></div></div>