[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 17:19:54 PST 2025
aaronpuchert wrote:
Good question. Which AST nodes could we visit here? Let's see some examples of initializing function pointers/references:
```c++
void f();
void (*fp)() = f;
void (*fp2)() = &f;
void (*fp3)() = fp;
void (&fr)() = f;
```
The (simplified) AST:
```
TranslationUnitDecl 0x55edc65d3778
|-FunctionDecl 0x55edc661d910 used f 'void ()'
|-VarDecl 0x55edc661dac0 used fp 'void (*)()' cinit
| `-ImplicitCastExpr 'void (*)()' <FunctionToPointerDecay>
| `-DeclRefExpr 'void ()' lvalue Function 0x55edc661d910 'f' 'void ()'
|-VarDecl 0x55edc661dbe8 fp2 'void (*)()' cinit
| `-UnaryOperator 'void (*)()' prefix '&' cannot overflow
| `-DeclRefExpr 'void ()' lvalue Function 0x55edc661d910 'f' 'void ()'
|-VarDecl 0x55edc661dd48 fp3 'void (*)()' cinit
| `-ImplicitCastExpr 'void (*)()' <LValueToRValue>
| `-DeclRefExpr 'void (*)()' lvalue Var 0x55edc661dac0 'fp' 'void (*)()'
`-VarDecl 0x55edc661dea0 fr 'void (&)()' cinit
`-DeclRefExpr 'void ()' lvalue Function 0x55edc661d910 'f' 'void ()'
```
The third and fourth declarations are tricky. I don't see an AST node that we could attach to for finding this. Perhaps we should adapt Sema to add casts for the attributes? Then we could always attach to the `ImplicitCastExpr`. (Note that the `LValueToRValue` cast is orthogonal and not relevant for this, it simply means we're reading `fp`.)
https://github.com/llvm/llvm-project/pull/67095
More information about the cfe-commits
mailing list