Hi,
I have a question regarding the source range of a FunctionDecl.
I am writing a matcher to match function declarations and use the FunctionDecl class’ getSourceRange() method to get the filename, the begin and the end locations of the declarations. For the most part, it works fine. But when a function with a #defined return type in a system header, then getSourceRange() does not give the expected filename and begin source location. For example, func_A below has this issue, but not func_B.
I have also checked with ast-dump and confirmed this is the case in clang 14, 16 and 17.
Is this what it is supposed to be, or is there an issue here? Thanks.
#include <stdbool.h>
// #define bool _Bool
// #define true 1
// #define false 0
bool func_A() {
return true;
}
_Bool func_B() {
return true;
}
$ clang -Xclang -ast-dump -fsyntax-only x.c
...
-FunctionDecl 0x564150ae9bc0 </usr/lib/llvm-16/lib/clang/16/include/stdbool.h:20:14, x.c:8:1> line:6:6 func_A 'bool ()'
| `-CompoundStmt 0x564150ae9cf8 <col:15, line:8:1>
| `-ReturnStmt 0x564150ae9ce8 <line:7:3, /usr/lib/llvm-16/lib/clang/16/include/stdbool.h:21:14>
| `-ImplicitCastExpr 0x564150ae9cd0 <col:14> 'bool' <IntegralToBoolean>
| `-IntegerLiteral 0x564150ae9cb0 <col:14> 'int' 1
`-FunctionDecl 0x564150ae9d30 <x.c:10:1, line:12:1> line:10:7 func_B 'bool ()'
`-CompoundStmt 0x564150ae9e20 <col:16, line:12:1>
`-ReturnStmt 0x564150ae9e10 <line:11:3, /usr/lib/llvm-16/lib/clang/16/include/stdbool.h:21:14>
`-ImplicitCastExpr 0x564150ae9df8 <col:14> 'bool' <IntegralToBoolean>
`-IntegerLiteral 0x564150ae9dd8 <col:14> 'int' 1