[clang] Thread safety analysis: Allocate FactEntrys with BumpPtrAllocator (PR #149660)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 28 01:04:56 PDT 2025
================
@@ -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:
Fair points. At the very least more comments above the ScopedLockableFactEntry::create and addManaged and wherever else needed to make the danger here clear.
https://github.com/llvm/llvm-project/pull/149660
More information about the cfe-commits
mailing list