[PATCH] D98724: Fix false negative in -Wthread-safety-attributes

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 24 09:46:23 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6a1c3051dbd: Fix false negative in -Wthread-safety-attributes (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98724/new/

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.333026.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210324/47be8264/attachment-0001.bin>


More information about the cfe-commits mailing list