[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Fri May 9 02:30:53 PDT 2025
================
@@ -4048,6 +4048,9 @@ def warn_thread_attribute_not_on_scoped_lockable_param : Warning<
"%0 attribute applies to function parameters only if their type is a "
"reference to a 'scoped_lockable'-annotated type">,
InGroup<ThreadSafetyAttributes>, DefaultIgnore;
+def warn_reentrant_capability_without_capability : Warning<
+ "ignoring %0 attribute on %1 without 'capability' attribute">,
----------------
melver wrote:
I'll generalize the diagnostic and make both parameters, so it can be reused if necessary. I think "requires" is not the right word here, because of the new ordering constraint, so I'll choose "must be preceded".
```
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4048,8 +4048,8 @@ def warn_thread_attribute_not_on_scoped_lockable_param : Warning<
"%0 attribute applies to function parameters only if their type is a "
"reference to a 'scoped_lockable'-annotated type">,
InGroup<ThreadSafetyAttributes>, DefaultIgnore;
-def warn_reentrant_capability_without_capability : Warning<
- "%0 attribute on %1 must be preceded by 'capability' attribute">,
+def warn_thread_attribute_requires_preceded : Warning<
+ "%0 attribute on %1 must be preceded by %2 attribute">,
InGroup<ThreadSafetyAttributes>, DefaultIgnore;
def err_attribute_argument_out_of_bounds_extra_info : Error<
"%0 attribute parameter %1 is out of bounds: "
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 68ddd286bce5..93d919102a9c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6249,8 +6249,8 @@ static void handleReentrantCapabilityAttr(Sema &S, Decl *D,
// This helps enforce a canonical style. Also avoids placing an additional
// branch into ProcessDeclAttributeList().
if (!D->hasAttr<CapabilityAttr>()) {
- S.Diag(AL.getLoc(), diag::warn_reentrant_capability_without_capability)
- << AL << cast<NamedDecl>(D);
+ S.Diag(AL.getLoc(), diag::warn_thread_attribute_requires_preceded)
+ << AL << cast<NamedDecl>(D) << "'capability'";
return;
}
```
https://github.com/llvm/llvm-project/pull/137133
More information about the cfe-commits
mailing list