[llvm-dev] [FileCheck] RFC: Add support for line anchors. (original) (raw)

Nathan James via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 17 09:23:19 PDT 2020


Hello,

I was wondering about extending FileCheck to enable creating line anchors. These are numeric variables that hold the value of the line number that where they were defined.

The motivation for this comes from test cases using clang-based diagnostics which often include notes attached to source locations in different parts of the file. In order to test for the correct location of the note, the line number has to be written explicitly or as an, often large, offset to the current line. This harms both readability and maintainability. Using this new system one could append a line of interest with an anchor-comment and refer back to it inside FileCheck.

I have created a basic patch that implements this here https://reviews.llvm.org/D84037 but it definitely needs a few looks over by people who are more clued up on the internal of FileCheck.

The current syntax, based off this patch, is as follows:

Here is a brief (contrived) example of the usage of this:

#define BAD_FUNCTION() badFunction() // LINE-ANCHOR: BAD_FUNC
// Further down in the file
  BAD_FUNCTION();
CHECK-NOTES: [[@LINE-1]]:3: warning: called a bad function
CHECK-NOTES :[[#BAD-FUNC]]:3: note: expanded from macro 'BAD_FUNCTION'

Regards, Nathan James



More information about the llvm-dev mailing list