[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 1 06:27:36 PDT 2024
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/67520 at github.com>
================
@@ -5794,6 +5794,30 @@ static void handleRequiresCapabilityAttr(Sema &S, Decl *D,
RequiresCapabilityAttr(S.Context, AL, Args.data(), Args.size());
D->addAttr(RCA);
+
+ if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
+
+ auto collectExprs = [](const FunctionDecl *FuncDecl) {
+ std::set<const ValueDecl*> Args;
+ for (const auto *A : FuncDecl->specific_attrs<RequiresCapabilityAttr>()) {
+ for (const Expr *E : A->args()) {
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
+ Args.insert(DRE->getDecl());
----------------
aaronpuchert wrote:
Yes, in fact most expressions won't be `DeclRefExpr`s but `MemberExpr`s. You get a `DeclRefExpr` when you reference a global variable, but most mutexes are going to be class members. When you reference them, you get a `MemberExpr` with an implicit `CXXThisExpr`. The TIL has facilities for semantically comparing expressions. You can use `SExprBuilder::translateAttrExpr` to translate an expression as `CapabilityExpr` and then compare them using `CapabilityExpr::equals`. This will do the right comparison, e.g. in `mu1, mu1` it will consider both expressions equal.
https://github.com/llvm/llvm-project/pull/67520
More information about the cfe-commits
mailing list