[clang] Thread Safety Analysis: Support guarded_by/pt_guarded_by with multiple capabilities (PR #186838)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 23 07:39:32 PDT 2026


================
@@ -2141,6 +2142,38 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
     Warnings.emplace_back(std::move(Warning), getNotes());
   }
 
+  void handleGuardedByAnyReadNotHeld(const NamedDecl *D,
+                                     ProtectedOperationKind POK,
+                                     ArrayRef<StringRef> LockNames,
+                                     SourceLocation Loc) override {
+    bool IsDeref;
+    switch (POK) {
+    case POK_VarAccess:
+    case POK_PassByRef:
+    case POK_ReturnByRef:
+    case POK_PassPointer:
+    case POK_ReturnPointer:
+      IsDeref = false;
+      break;
+    case POK_VarDereference:
+    case POK_PtPassByRef:
+    case POK_PtReturnByRef:
+    case POK_PtPassPointer:
+    case POK_PtReturnPointer:
+      IsDeref = true;
+      break;
+    case POK_FunctionCall:
+      llvm_unreachable("POK_FunctionCall not applicable here");
+    }
+    SmallVector<std::string, 2> Quoted;
+    for (StringRef Name : LockNames)
+      Quoted.push_back(("'" + Name + "'").str());
+    PartialDiagnosticAt Warning(Loc, S.PDiag(diag::warn_requires_any_of_locks)
+                                         << D << IsDeref
+                                         << llvm::join(Quoted, ", "));
----------------
melver wrote:

Done.

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


More information about the cfe-commits mailing list