================
@@ -115,7 +115,25 @@ class RAIIMutexDescriptor {
       return false;
     const IdentifierInfo *II =
         cast<CXXRecordDecl>(C->getDecl()->getParent())->getIdentifier();
-    return II == Guard;
+    if (II != Guard)
+      return false;
+
+    // For unique_lock, check if it's constructed with a ctor that takes the 
tag
+    // type defer_lock_t. In this case, the lock is not acquired.
+    if constexpr (std::is_same_v<T, CXXConstructorCall>) {
+      if (GuardName == "unique_lock" && C->getNumArgs() >= 2) {
+        const Expr *SecondArg = C->getArgExpr(1);
+        QualType ArgType = SecondArg->getType().getNonReferenceType();
+        QualType UnqualifiedType = ArgType.getUnqualifiedType();
+        if (const auto *RD = UnqualifiedType->getAsRecordDecl();
----------------
NagyDonat wrote:

```suggestion
        if (const auto *RD = ArgType->getAsRecordDecl();
```
As you only use this `QualType` to access its inner `Type` with `operator->` 
(essentially using it as a smart pointer) there is no need to call 
`getUnqualifiedType`. (The presence or absence of qualifiers is irrelevant for 
this application.)

Note that calling `getUnqualifiedType()` may change the result because it can 
strip some `typedef` layers, but only if that's needed to get a fully 
unqualified type (e.g. after `typedef int Integer; typedef const Integer 
CInteger;` the type `CInteger` is converted to `const Integer`). If you want to 
ensure that all typedef layers are always stripped, you should use 
`getCanonicalType()`, but I think that's overkill in this particular case.

https://github.com/llvm/llvm-project/pull/168338
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to