[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 22 00:28:22 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
This was much easier than expected actually.
I'm sure I'm missing a lot of changes and test coverage though.
@<!-- -->aaronpuchert I'm starting a new review here instead of continuing the one in Phab since this is a completely different attempt. I hope that's ok.
---
Full diff: https://github.com/llvm/llvm-project/pull/67095.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/Attr.td (+3-3)
- (modified) clang/test/Sema/warn-thread-safety-analysis.c (+11)
``````````diff
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 21a3b5226623cf2..7eab87dac6921f1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3305,7 +3305,7 @@ def ReleaseCapability : InheritableAttr {
let Documentation = [ReleaseCapabilityDocs];
}
-def RequiresCapability : InheritableAttr {
+def RequiresCapability : DeclOrTypeAttr {
let Spellings = [Clang<"requires_capability", 0>,
Clang<"exclusive_locks_required", 0>,
Clang<"requires_shared_capability", 0>,
@@ -3314,8 +3314,8 @@ def RequiresCapability : InheritableAttr {
let LateParsed = 1;
let TemplateDependent = 1;
let ParseArgumentsAsUnevaluated = 1;
- let InheritEvenIfAlreadyPresent = 1;
- let Subjects = SubjectList<[Function]>;
+ /*let InheritEvenIfAlreadyPresent = 1;*/
+ /*let Subjects = SubjectList<[Function]>;*/
let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 0>,
Clang<"shared_locks_required", 0>]>];
let Documentation = [Undocumented];
diff --git a/clang/test/Sema/warn-thread-safety-analysis.c b/clang/test/Sema/warn-thread-safety-analysis.c
index 642ea88ec3c96f7..cd852efac21cb81 100644
--- a/clang/test/Sema/warn-thread-safety-analysis.c
+++ b/clang/test/Sema/warn-thread-safety-analysis.c
@@ -136,6 +136,17 @@ int main(void) {
// Cleanup happens automatically -> no warning.
}
+ /// Function pointers
+ {
+ int __attribute__((requires_capability(&mu1))) (*function_ptr)(int) = Foo_fun1;
+
+ function_ptr(5); // expected-warning {{calling function 'function_ptr' requires holding mutex 'mu1'}}
+
+ mutex_exclusive_lock(&mu1);
+ int five = function_ptr(5);
+ mutex_exclusive_unlock(&mu1);
+ }
+
return 0;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/67095
More information about the cfe-commits
mailing list