[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 15:24:27 PDT 2024
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
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>
================
@@ -2263,6 +2265,28 @@ static bool neverReturns(const CFGBlock *B) {
return false;
}
+void ThreadSafetyAnalyzer::checkMismatchedFunctionAttrs(
+ const FunctionDecl *FD) {
+ FD = FD->getMostRecentDecl();
+
+ auto collectCapabilities = [&](const FunctionDecl *FD) {
+ SmallVector<CapabilityExpr> Args;
+ for (const auto *A : FD->specific_attrs<RequiresCapabilityAttr>()) {
+ for (const Expr *E : A->args())
+ Args.push_back(SxBuilder.translateAttrExpr(E, nullptr));
+ }
+ return Args;
+ };
+
+ auto FDArgs = collectCapabilities(FD);
+ for (const FunctionDecl *D = FD->getPreviousDecl(); D;
+ D = D->getPreviousDecl()) {
+ auto DArgs = collectCapabilities(D);
+ if (DArgs.size() != FDArgs.size())
+ Handler.handleAttributeMismatch(FD, D);
----------------
aaronpuchert wrote:
In #110523 we had a similar problem and decided to compare the sets one-by-one (search for `zip_longest`). The attributes do not have a meaningful order, but I don't see a benefit in allowing different orders. It's probably better for readability if we enforce consistent ordering.
But we can certainly also do a pairwise comparison to compute the difference sets and then emit warnings depending on which set contains `CapabilityExpr`s.
https://github.com/llvm/llvm-project/pull/67520
More information about the cfe-commits
mailing list