From: Aaron Puchert Date: Wed, 24 Mar 2021 16:45:22 +0000 (+0100) Subject: Fix false negative in -Wthread-safety-attributes X-Git-Tag: llvmorg-14-init~11384 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6a1c3051dbd2cc5ccc70272890cf38d11dca9c7;p=platform%2Fupstream%2Fllvm.git Fix false negative in -Wthread-safety-attributes The original implementation didn't fire on non-template classes when a base class was an instantiation of a template with a dependent base. In that case the base of the base is dependent as seen from the base, but not from the class we're interested in, which isn't a template. Also it simplifies the code a lot. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D98724 --- diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c490104..b39460d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -513,16 +513,9 @@ static bool checkRecordDeclForAttr(const RecordDecl *RD) { // Else check if any base classes have the attribute. if (const auto *CRD = dyn_cast(RD)) { - CXXBasePaths BPaths(false, false); - if (CRD->lookupInBases( - [](const CXXBaseSpecifier *BS, CXXBasePath &) { - const auto &Ty = *BS->getType(); - // If it's type-dependent, we assume it could have the attribute. - if (Ty.isDependentType()) - return true; - return Ty.castAs()->getDecl()->hasAttr(); - }, - BPaths, true)) + if (!CRD->forallBases([](const CXXRecordDecl *Base) { + return !Base->hasAttr(); + })) return true; } return false; diff --git a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp index 6ad0f87..b6e9c05 100644 --- a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp @@ -1295,6 +1295,11 @@ struct SLDerived2 : public SLTemplateClass { // expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' or 'scoped_lockable' attribute}} }; +struct SLDerived3 : public SLTemplateDerived { + ~SLDerived3() UNLOCK_FUNCTION(); // \ + // expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived3' isn't annotated with 'capability' or 'scoped_lockable' attribute}} +}; + //----------------------------------------------------- // Parsing of member variables and function parameters //------------------------------------------------------