[PATCH] D98724: Fix false negative in -Wthread-safety-attributes
Aaron Puchert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 16 10:43:40 PDT 2021
aaronpuchert created this revision.
aaronpuchert added a reviewer: aaron.ballman.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98724
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/warn-thread-safety-parsing.cpp
Index: clang/test/SemaCXX/warn-thread-safety-parsing.cpp
===================================================================
--- clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1295,6 +1295,11 @@
// 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<int> {
+ ~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
//------------------------------------------------------
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -513,16 +513,9 @@
// Else check if any base classes have the attribute.
if (const auto *CRD = dyn_cast<CXXRecordDecl>(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<RecordType>()->getDecl()->hasAttr<AttrType>();
- },
- BPaths, true))
+ if (!CRD->forallBases([](const CXXRecordDecl *Base) {
+ return !Base->hasAttr<AttrType>();
+ }))
return true;
}
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98724.331040.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210316/1f2843db/attachment.bin>
More information about the cfe-commits
mailing list