[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:29 PST 2025


================
@@ -515,8 +515,18 @@ Warning flags
   + ``-Wthread-safety-analysis``: The core analysis.
   + ``-Wthread-safety-precise``: Requires that mutex expressions match precisely.
        This warning can be disabled for code which has a lot of aliases.
-  + ``-Wthread-safety-reference``: Checks when guarded members are passed by reference.
-
+  + ``-Wthread-safety-reference``: Checks when guarded variables are passed by reference.
+
+* ``-Wthread-safety-addressof``: Warn when the address of guarded variables is
+  taken (``&var``). Since taking the address of a variable does *not
+  necessarily imply a read or write*, the warning is off by default to avoid
+  false positives. In codebases that prefer passing pointers rather than
+  references (for C++ codebases), or passing pointers is ubiquitous (for C
+  codebases), enabling this warning will result in fewer false negatives; for
+  example, where the manipulation of common data structures is done via
+  functions that take pointers to instances of the data structure. Note,
+  however, that the analysis does not track pointers, and false positives *and*
+  negatives are still possible.
----------------
aaronpuchert wrote:

I'm not sure if we should still mark this as experimental in case this doesn't turn out so well.

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


More information about the cfe-commits mailing list