================ @@ -941,43 +966,68 @@ class LockableFactEntry : public FactEntry { } }; -class ScopedLockableFactEntry : public FactEntry { +enum UnderlyingCapabilityKind { + UCK_Acquired, ///< Any kind of acquired capability. + UCK_ReleasedShared, ///< Shared capability that was released. + UCK_ReleasedExclusive, ///< Exclusive capability that was released. +}; + +struct UnderlyingCapability { + CapabilityExpr Cap; + UnderlyingCapabilityKind Kind; +}; + +class ScopedLockableFactEntry final + : public FactEntry, + private llvm::TrailingObjects<ScopedLockableFactEntry, + UnderlyingCapability> { + friend TrailingObjects; + private: - enum UnderlyingCapabilityKind { - UCK_Acquired, ///< Any kind of acquired capability. - UCK_ReleasedShared, ///< Shared capability that was released. - UCK_ReleasedExclusive, ///< Exclusive capability that was released. - }; + const unsigned ManagedCapacity; + unsigned ManagedSize = 0; - struct UnderlyingCapability { - CapabilityExpr Cap; - UnderlyingCapabilityKind Kind; - }; + ScopedLockableFactEntry(const CapabilityExpr &CE, SourceLocation Loc, + SourceKind Src, unsigned ManagedCapacity) + : FactEntry(ScopedLockable, CE, LK_Exclusive, Loc, Src), + ManagedCapacity(ManagedCapacity) {} - SmallVector<UnderlyingCapability, 2> UnderlyingMutexes; + void addManaged(const CapabilityExpr &M, UnderlyingCapabilityKind UCK) { + assert(ManagedSize < ManagedCapacity); ---------------- melver wrote:
I feel this should not just be an assert, but a runtime check that also aborts in release builds. This bounds check is too critical, and it looks like the caller getting the capacity right is critical. Either that, or somehow designing this new API in a way that does not require passing ManagedCapacity (unclear how, perhaps an API that takes a parameter pack of CapabilityExprs to be added, but seems non-trivial when wanting to distinguish Exlusive/Shared/etc.). https://github.com/llvm/llvm-project/pull/149660 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits