Skip to content

Commit a6a1c30

Browse files
committed
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
1 parent 14b2ec9 commit a6a1c30

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,9 @@ static bool checkRecordDeclForAttr(const RecordDecl *RD) {
513513

514514
// Else check if any base classes have the attribute.
515515
if (const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
516-
CXXBasePaths BPaths(false, false);
517-
if (CRD->lookupInBases(
518-
[](const CXXBaseSpecifier *BS, CXXBasePath &) {
519-
const auto &Ty = *BS->getType();
520-
// If it's type-dependent, we assume it could have the attribute.
521-
if (Ty.isDependentType())
522-
return true;
523-
return Ty.castAs<RecordType>()->getDecl()->hasAttr<AttrType>();
524-
},
525-
BPaths, true))
516+
if (!CRD->forallBases([](const CXXRecordDecl *Base) {
517+
return !Base->hasAttr<AttrType>();
518+
}))
526519
return true;
527520
}
528521
return false;

clang/test/SemaCXX/warn-thread-safety-parsing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,11 @@ struct SLDerived2 : public SLTemplateClass<int> {
12951295
// expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
12961296
};
12971297

1298+
struct SLDerived3 : public SLTemplateDerived<int> {
1299+
~SLDerived3() UNLOCK_FUNCTION(); // \
1300+
// expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived3' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
1301+
};
1302+
12981303
//-----------------------------------------------------
12991304
// Parsing of member variables and function parameters
13001305
//------------------------------------------------------

0 commit comments

Comments
 (0)