Open Quuxplusone opened 2 years ago
$ clang --version
Ubuntu clang version 11.0.0-2~ubuntu20.04.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang-query-12 --version
LLVM (http://llvm.org/):
LLVM version 12.0.0
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: znver2
Can confirm that this occurs on trunk and is not expected behavior. https://godbolt.org/z/jcPKGo1sW
The issue is not specific to variableArrayType(), this happens for all type matchers: https://godbolt.org/z/GadjG3M3n
The issue is that DynTypedNode::getSourceRange() has no idea how to find the source range for a type that is not a type location because types don't store their source location directly (for performance reasons). But the MatchQuery::run() method looks to see if the matched location has a valid source location before attempting to print a text diagnostic from it. This is why set output diag
is the failure point -- other outputs don't require a valid source location.
A workaround for this is to wrap your type matcher with loc()
to convert it to a TypeLoc
matcher that has source location information. e.g., https://godbolt.org/z/qa18escqG
Using the example given on the AST Matcher Reference for the Matcher
running the example snippet will not produce the desired output
The match occurs but no actual information is returned.
Using any of:
will give output.
But:
the default, will return it to no output.
This can be simplified to the most simple
variableArrayType()
expression with the same result (also on a bigger file)This is of course in contrast to other matchers like
varDecl()
that will always outputOther matchers have a similar issue:
Apologies if this is documented behavior, but i haven't found it anywhere.