[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

Cory Fields via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 11 11:45:39 PDT 2025


theuni wrote:

> > On a related note, do we emit `-Wthread-safety-negative` for reentrant locks? I don't remember that we carved out an exception for that, and we probably should.
> 
> We do - and it's deliberate on my part as I've been trying to indicate that there might be valid use cases for that. While conceptually contradictory, there might be cases where developers want to ensure a reentrant mutex is NOT held before entering a function.

Chiming in here with a use-case...

My software currently contains a nasty global recursive lock that we hope to (over a long period of time, likely years) convert to non-recursive.

In the meantime, and during the refactor, it's helpful to be able to mark some functions as `EXCLUSIVE_LOCKS_REQUIRED(!recursive_mut)` even though technically it wouldn't be a problem.

Ideally, that would even "convert" the lock, as far as the annotations go, to non-recursive. That way, from that point on, functions further down the call-stack could no longer double-lock. Though, I suppose that's arguably a different feature altogether.

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


More information about the cfe-commits mailing list