[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
- Previous message: [llvm-dev] Switch to ld.bfd tombstone behavior by default
- Next message: [llvm-dev] [cfe-dev] [FileCheck] RFC: Add support for line anchors.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
- Added a command line option called
anchor-prefixwhich is a comma-seperated list of prefixes to be used when declaring anchors. This is defaulted toLINE-ANCHOR - To declare a anchor in the test file use
LINE-ANCHOR: ANCHOR_NAMEnote: If you specify a different anchor-prefix using the command line, use that name instead ofLINE-ANCHORANCHOR_NAME Follows the rules all other variable names aside from the fact it can't start with '$'. - When referring to an anchor in a check use the same numeric
variable syntax that FileCheck already supports:
CHECK: [[#ANCHOR_NAME]][[#ANCHOR_NAME+1]]
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
- Previous message: [llvm-dev] Switch to ld.bfd tombstone behavior by default
- Next message: [llvm-dev] [cfe-dev] [FileCheck] RFC: Add support for line anchors.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]