================
@@ -168,6 +228,98 @@ class FactEntry : public CapabilityExpr {
   }
 };
 
+/// The conditional fact of one try-acquire call's stored result: created at 
the
+/// call, resolved by the branches on the result, and kept afterwards as the
+/// record of what they proved, in one of these states:
+///
+///   Conditional    The result is unknown here: the capability is held iff it
+///                  is truthy. The only state that is a (possible) hold.
+///   ProvedHeld     The result is truthy on every path here, and the hold it
+///                  proved is live: one level of the definite fact comes from
+///                  branching on this call.
+///
+/// Two try facts of one identity meet only at a join.
+class TryFactEntry final : public FactEntry {
+public:
+  enum class State : uint8_t { Conditional, ProvedHeld };
+
+private:
+  /// The try-acquire call whose result created this fact state.
+  const Expr *Origin;
+
+  State St : 8;
+
+  TryFactEntry(const CapabilityExpr &CE, LockKind LK, SourceLocation Loc,
+               SourceKind Src, const Expr *Origin)
+      : FactEntry(TryFact, CE, LK, Loc, Src), Origin(Origin),
+        St(State::Conditional) {
+    assert(Origin && "a try fact speaks about a call");
+  }
+
+public:
+  static TryFactEntry *create(llvm::BumpPtrAllocator &Alloc,
+                              const TryFactEntry &Other) {
+    return new (Alloc) TryFactEntry(Other);
+  }
+
+  static TryFactEntry *create(llvm::BumpPtrAllocator &Alloc,
+                              const CapabilityExpr &CE, LockKind LK,
+                              SourceLocation Loc, SourceKind Src,
+                              const Expr *Origin) {
+    return new (Alloc) TryFactEntry(CE, LK, Loc, Src, Origin);
+  }
+
+  const Expr *origin() const { return Origin; }
+  State state() const { return St; }
+  bool conditional() const { return St == State::Conditional; }
+  bool provedHeld() const { return St == State::ProvedHeld; }
+
+  const TryFactEntry *withState(FactManager &FactMan, State S) const;
+
+  /// The definite fact this try fact's success proves: the same
+  /// acquisition -- kind, source and location -- now held.
+  const LockableFactEntry *asDefinite(FactManager &FactMan) const;
+
+  /// The state two try facts of one identity meet in, one on each side of a
+  /// join point: two equal states meet in themselves, and anything else meets
+  /// in Conditional, since a proof about one side's paths is no proof about
+  /// the other's.
+  ///
+  /// This is the meet of the states, not the outcome of the join. What the
+  /// merged fact becomes, and what happens to the definite facts a
+  /// ProvedHeld side proved, is the responsibility of the merge algorithm.
+  static State joinStates(State A, State B) {
+    if (A == B)
+      return A;
+    return State::Conditional;
+  }
+
+  /// A try fact is never dispatched through the one-fact-per-capability
+  /// protocol below: the analyzer orchestrates its transitions itself.
+  void
+  handleRemovalFromIntersection(const FactSet &FSet, FactManager &FactMan,
+                                SourceLocation JoinLoc, LockErrorKind LEK,
+                                ThreadSafetyHandler &Handler) const override {
+    llvm_unreachable("a try fact is lost through its own join rules");
+  }
+
+  void handleLock(FactSet &FSet, FactManager &FactMan, const FactEntry &entry,
+                  ThreadSafetyHandler &Handler) const override {
+    llvm_unreachable("a try fact is not a hold to reacquire");
+  }
+
+  void handleUnlock(FactSet &FSet, FactManager &FactMan,
+                    const CapabilityExpr &Cp, SourceLocation UnlockLoc,
+                    bool FullyRemove,
+                    ThreadSafetyHandler &Handler) const override {
+    llvm_unreachable("a try fact is not a hold to release");
+  }
----------------
aaronpuchert wrote:

This part is a bit weird, because we're now handling some facts via virtual 
function dispatch, others by looking at the type. I guess that if we can't make 
this fit with the existing framework (though I don't yet understand why), we 
should abandon virtual functions entirely.

https://github.com/llvm/llvm-project/pull/241550
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to