[clang] Thread safety analysis: Allocate FactEntrys with BumpPtrAllocator (PR #149660)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 27 12:31:31 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);
----------------
aaronpuchert wrote:
For a general API, I get your point. But this is used in two places. Also, `FactEntry`s are made immutable pretty soon. They're only modified before being added to the `FactManager`. So with good test coverage you should notice any discrepancy via tests.
In principle a pack is a nice idea, but the different types of managed capabilities complicate this somewhat. I'm not sure if this would still be readable.
https://github.com/llvm/llvm-project/pull/149660
More information about the cfe-commits
mailing list