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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 5 06:58:12 PDT 2025


================
@@ -7223,4 +7225,10 @@ class TestNegativeWithReentrantMutex {
   }
 };
 
+typedef int __attribute__((capability("role"), reentrant_capability)) ThreadRole;
+ThreadRole FlightControl1, FlightControl2;
+void dispatch_log(const char *msg) __attribute__((requires_capability(!FlightControl1 && !FlightControl2))) {} // \
+  // expected-warning{{'ThreadRole' (aka 'int') is marked reentrant but used as a negative capability; this may be contradictory}} \
----------------
AaronBallman wrote:

Oooh, the reason this test passes despite the `DefaultIgnore` is because the diagnostic is enabled by `-Wthread-safety` which is the only way to enable any thread safety diagnostics.

If we want the diagnostic to be ignored by default, we'd leave the group out of `-Wthread-safety` but that could get awkward (what if you enable just the pedantic warning and nothing else? ew.)

So I think we should drop the `DefaultIgnore` above to avoid confusion.

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


More information about the cfe-commits mailing list