[clang] [analyzer] Fix false positive for mutexes inheriting mutex_base (PR #106240)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 01:59:46 PDT 2024


================
@@ -241,10 +241,14 @@ BlockInCriticalSectionChecker::checkDescriptorMatch(const CallEvent &Call,
   return std::nullopt;
 }
 
-static const MemRegion *skipBaseClassRegion(const MemRegion *Reg) {
-  while (const auto *BaseClassRegion = dyn_cast<CXXBaseObjectRegion>(Reg)) {
+static const MemRegion *skipStdBaseClassRegion(const MemRegion *Reg) {
+  do {
+    assert(Reg);
+    const auto *BaseClassRegion = dyn_cast<CXXBaseObjectRegion>(Reg);
+    if (!BaseClassRegion || !BaseClassRegion->getDecl()->isInStdNamespace())
----------------
NagyDonat wrote:

`<pedantery>`
> isInStdNamespace only works if the decl is exactly within std. Any nested namespaces beyond std, or class scopes are rejected even if their parents reside within std.
IIRC `isInStdNamespace` also accepts anonymous subnamespaces of `std` (so that kind of implementation detail won't cause problems at least).
`</pedantery>`

https://github.com/llvm/llvm-project/pull/106240


More information about the cfe-commits mailing list