[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 19 09:14:36 PDT 2025
================
@@ -3566,6 +3565,38 @@ void releaseMemberCall() {
ReleasableMutexLock lock(&obj.mu);
releaseMember(obj, lock);
}
+#ifdef __cpp_guaranteed_copy_elision
+// expected-note at +2{{mutex acquired here}}
+// expected-note at +1{{see attribute on function here}}
+RelockableScope returnUnmatchTest() EXCLUSIVE_LOCK_FUNCTION(mu){
+ // expected-note at +1{{mutex acquired here}}
+ return RelockableScope(&mu2); // expected-warning{{mutex managed by '<temporary>' is 'mu2' instead of 'mu'}}
+} // expected-warning{{mutex 'mu2' is still held at the end of function}}
+ // expected-warning at -1{{expecting mutex 'mu' to be held at the end of function}}
+
+// expected-note at +2{{mutex acquired here}}
+// expected-note at +1{{see attribute on function here}}
+RelockableScope returnMoreTest() EXCLUSIVE_LOCK_FUNCTION(mu, mu2){
+ return RelockableScope(&mu); // expected-warning{{mutex 'mu2' not managed by '<temporary>'}}
+} // expected-warning{{expecting mutex 'mu2' to be held at the end of function}}
+
+// expected-note at +1{{see attribute on function here}}
+DoubleMutexLock returnFewerTest() EXCLUSIVE_LOCK_FUNCTION(mu){
+ // expected-note at +1{{mutex acquired here}}
+ return DoubleMutexLock(&mu,&mu2); // expected-warning{{did not expect mutex 'mu2' to be managed by '<temporary>'}}
----------------
aaronpuchert wrote:
```suggestion
return DoubleMutexLock(&mu, &mu2); // expected-warning{{did not expect mutex 'mu2' to be managed by '<temporary>'}}
```
https://github.com/llvm/llvm-project/pull/131831
More information about the cfe-commits
mailing list