[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 03:12:29 PDT 2023
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/67095/clang at github.com>
================
@@ -8141,6 +8141,16 @@ static void handleRequiresCapabilityAttr(Sema &S, Decl *D,
if (!AL.checkAtLeastNumArgs(S, 1))
return;
+ // We allow this on function declaration as well as
+ // variable declarations of function pointer type.
+ if (!D->isFunctionPointerType() && !isa<FunctionDecl>(D)) {
----------------
tbaederr wrote:
Yeah we attach the attribute to the declaration later in this function:
```c++
RequiresCapabilityAttr *RCA = ::new (S.Context)
RequiresCapabilityAttr(S.Context, AL, Args.data(), Args.size());
D->addAttr(RCA);
```
and in `ThreadSafety.cpp` we then check the decl for the attribute in `VisitCallExpr()`:
```c++
auto *D = dyn_cast_or_null<NamedDecl>(Exp->getCalleeDecl());
if(!D || !D->hasAttrs())
return;
```
for the function pointer case, `D` will be the `VarDecl`, which now has the attribute attached.
https://github.com/llvm/llvm-project/pull/67095
More information about the cfe-commits
mailing list