[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 10:14:18 PST 2025
================
@@ -6087,9 +6215,37 @@ class Return {
const Foo &returns_constref_shared_locks_required() SHARED_LOCKS_REQUIRED(mu) {
return foo;
}
+
+ Foo *returns_ptr_exclusive_locks_required() EXCLUSIVE_LOCKS_REQUIRED(mu) {
+ return &foo;
+ }
+
+ Foo *returns_pt_ptr_exclusive_locks_required() EXCLUSIVE_LOCKS_REQUIRED(mu) {
+ return foo_ptr;
+ }
+
+ Foo *returns_ptr_shared_locks_required() SHARED_LOCKS_REQUIRED(mu) {
+ return &foo; // expected-warning {{returning pointer to variable 'foo' requires holding mutex 'mu' exclusively}}
+ }
+
+ Foo *returns_pt_ptr_shared_locks_required() SHARED_LOCKS_REQUIRED(mu) {
+ return foo_ptr; // expected-warning {{returning pointer 'foo_ptr' requires holding mutex 'mu' exclusively}}
+ }
+
+ const Foo *returns_constptr_shared_locks_required() SHARED_LOCKS_REQUIRED(mu) {
+ return &foo;
+ }
+
+ const Foo *returns_pt_constptr_shared_locks_required() SHARED_LOCKS_REQUIRED(mu) {
+ return foo_ptr;
+ }
Foo *returns_ptr() {
- return &foo; // FIXME -- Do we want to warn on this ?
+ return &foo; // expected-warning {{returning pointer to variable 'foo' requires holding mutex 'mu' exclusively}}
+ }
+
+ Foo *returns_pt_ptr() {
----------------
melver wrote:
Done.
https://github.com/llvm/llvm-project/pull/127396
More information about the cfe-commits
mailing list