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

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 11 08:26:58 PDT 2025


================
@@ -4222,6 +4222,11 @@ def warn_fun_requires_lock_precise :
   InGroup<ThreadSafetyPrecise>, DefaultIgnore;
 def note_found_mutex_near_match : Note<"found near match '%0'">;
 
+// Pedantic thread safety warnings enabled by default
+def warn_thread_reentrant_with_negative_capability : Warning<
+  "%0 is marked reentrant but used as a negative capability; this may be contradictory">,
+  InGroup<ThreadSafetyPedantic>, DefaultIgnore;
----------------
melver wrote:

My reasoning for the flag is to compromise: by default it doesn't make sense, but advanced users might have valid uses (see example in my other comment).

In general, I'd still prefer to not have this warning at all - but I understand your original reasoning, and see that in most cases it's a bug. We try to be helpful in the common case, but in the uncommon case where there is an advanced synchronization protocol, the user is free to disable the "pedantic" group of warnings.

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


More information about the cfe-commits mailing list