Poor DeclStmt source range with leading [[attributes]]?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Poor DeclStmt source range with leading [[attributes]]?

Renato Golin via cfe-dev
Seen with various versions of Clang, 8.0.0 and recent trunk,

> $ cat test.cc
> void f() {
>  [[maybe_unused]] int i;
> }

> clang++ -c -Xclang -ast-dump test.cc
[...]
> `-FunctionDecl 0x8ab1148 <test.cc:1:1, line:3:1> line:1:6 f 'void ()'
>   `-CompoundStmt 0x8ab1320 <col:10, line:3:1>
>     `-DeclStmt 0x8ab1308 <line:2:19, col:24>
>       `-VarDecl 0x8ab1248 <col:19, col:23> col:23 i 'int'
>         `-UnusedAttr 0x8ab12b0 <col:4> maybe_unused

Note how the DeclStmt (and the enclosed VarDecl) only start with the
"int" at column 19, not with the "[[" at column 1.  (And that matches
what you programmatically obtain from that DeclStmt via
getSourceRange/getBeginLoc.)

Is there some good reason for that, or is it a bug that should get fixed?

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Poor DeclStmt source range with leading [[attributes]]?

Renato Golin via cfe-dev
On 30/09/2019 16:01, Stephan Bergmann wrote:

> Seen with various versions of Clang, 8.0.0 and recent trunk,
>
>> $ cat test.cc
>> void f() {
>>  [[maybe_unused]] int i;
>> }
>
>> clang++ -c -Xclang -ast-dump test.cc
> [...]
>> `-FunctionDecl 0x8ab1148 <test.cc:1:1, line:3:1> line:1:6 f 'void ()'
>>   `-CompoundStmt 0x8ab1320 <col:10, line:3:1>
>>     `-DeclStmt 0x8ab1308 <line:2:19, col:24>
>>       `-VarDecl 0x8ab1248 <col:19, col:23> col:23 i 'int'
>>         `-UnusedAttr 0x8ab12b0 <col:4> maybe_unused
>
> Note how the DeclStmt (and the enclosed VarDecl) only start with the
> "int" at column 19, not with the "[[" at column 1.  (And that matches
> what you programmatically obtain from that DeclStmt via
> getSourceRange/getBeginLoc.)
>
> Is there some good reason for that, or is it a bug that should get fixed?

Assuming it's a bug, I started <https://reviews.llvm.org/D68581>
"Include leading attributes in DeclStmt's SourceRange" now.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev