[clang] Thread Safety Analysis: Support warning on taking address of guarded variables (PR #123063)

Aaron Puchert via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 07:59:30 PST 2025


================
@@ -133,7 +134,12 @@ int main(void) {
 
   Foo_func3(5);
 
+#ifdef CHECK_ADDRESSOF
+  set_value(&a_, 0); // expected-warning{{calling function 'set_value' requires holding mutex 'foo_.mu_' exclusively}} \
+                        expected-warning{{taking address of variable 'a_' requires holding mutex 'foo_.mu_'}}
----------------
aaronpuchert wrote:

Something like this should also work:
```suggestion
  set_value(&a_, 0); // expected-warning{{calling function 'set_value' requires holding mutex 'foo_.mu_' exclusively}}
                     // expected-warning at -1{{taking address of variable 'a_' requires holding mutex 'foo_.mu_'}}
```

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


More information about the cfe-commits mailing list