@@ -1074,7 +1074,7 @@ class ThreadSafetyAnalyzer {
10741074 void checkPtAccess (const FactSet &FSet, const Expr *Exp, AccessKind AK,
10751075 ProtectedOperationKind POK);
10761076
1077- void checkMismatchedFunctionAttrs (const FunctionDecl *FD );
1077+ void checkMismatchedFunctionAttrs (const NamedDecl *ND );
10781078};
10791079
10801080} // namespace
@@ -2265,25 +2265,27 @@ static bool neverReturns(const CFGBlock *B) {
22652265 return false ;
22662266}
22672267
2268- void ThreadSafetyAnalyzer::checkMismatchedFunctionAttrs (
2269- const FunctionDecl *FD) {
2270- FD = FD->getMostRecentDecl ();
2268+ void ThreadSafetyAnalyzer::checkMismatchedFunctionAttrs ( const NamedDecl *ND) {
22712269
2272- auto collectCapabilities = [&](const FunctionDecl *FD ) {
2273- SmallVector<CapabilityExpr> Args;
2274- for (const auto *A : FD ->specific_attrs <RequiresCapabilityAttr>()) {
2270+ auto collectCapabilities = [&](const Decl *D ) {
2271+ llvm:: SmallVector<CapabilityExpr> Args;
2272+ for (const auto *A : D ->specific_attrs <RequiresCapabilityAttr>()) {
22752273 for (const Expr *E : A->args ())
22762274 Args.push_back (SxBuilder.translateAttrExpr (E, nullptr ));
22772275 }
22782276 return Args;
22792277 };
22802278
2281- auto FDArgs = collectCapabilities (FD );
2282- for (const FunctionDecl *D = FD ->getPreviousDecl (); D;
2279+ auto NDArgs = collectCapabilities (ND );
2280+ for (const Decl *D = ND ->getPreviousDecl (); D;
22832281 D = D->getPreviousDecl ()) {
22842282 auto DArgs = collectCapabilities (D);
2285- if (DArgs.size () != FDArgs.size ())
2286- Handler.handleAttributeMismatch (FD, D);
2283+
2284+ for (const auto &[A, B] : zip_longest (NDArgs, DArgs)) {
2285+ if (!A || !B || !(*A).equals (*B)) {
2286+ Handler.handleAttributeMismatch (cast<NamedDecl>(ND), cast<NamedDecl>(D));
2287+ }
2288+ }
22872289 }
22882290}
22892291
@@ -2306,8 +2308,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
23062308 const NamedDecl *D = walker.getDecl ();
23072309 CurrentFunction = dyn_cast<FunctionDecl>(D);
23082310
2309- if (CurrentFunction )
2310- checkMismatchedFunctionAttrs (CurrentFunction );
2311+ if (isa<FunctionDecl, ObjCMethodDecl>(D) )
2312+ checkMismatchedFunctionAttrs (D );
23112313
23122314 if (D->hasAttr <NoThreadSafetyAnalysisAttr>())
23132315 return ;
0 commit comments