[llvm-branch-commits] [clang] Thread Safety Analysis: Track try-acquired capabilities as a ternary try-held state (PR #220635)

Aaron Puchert via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 15 16:53:02 PST 2026


================
@@ -133,6 +184,25 @@ class FactEntry : public CapabilityExpr {
   /// Where it was acquired.
   SourceLocation AcquireLoc;
 
+  /// The try-acquire call this fact originates from (or null), and whether
+  /// the capability is still only conditionally ("try") held: acquired by
+  /// that call but not yet branched on its result, so held only on the paths
+  /// where the call succeeded. Facts promoted to held on the call's success
+  /// edge keep their origin (with the flag cleared), so that a later join
+  /// with a path where the try-acquire failed can be recognized. Facts
+  /// upgraded by an unconditional acquire or assert clear this: their held
+  /// state is not proved by the call's success, so a branch on its result
+  /// must not resolve them (a reentrant acquire instead deepens the fact,
+  /// keeping the origin for its still conditional top level). A try-held
+  /// fact whose paths merged different origins loses its origin and can
+  /// never be resolved; it stays try-held until the analysis loses track
+  /// of it.
+  /// (callexpr, true)  : try-held state from callexpr
+  /// (callexpr, false) : held state from callexpr
+  /// (nullptr, true)   : try-held state from multiple sources
+  /// (nullptr, false)  : held state from definitive sources
+  llvm::PointerIntPair<const Expr *, 1, bool> TryLock;
----------------
aaronpuchert wrote:

Compared to other PR, I like that we keep the one-to-one relationship between facts and locks.

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


More information about the llvm-branch-commits mailing list