================ @@ -103,14 +103,46 @@ using namespace std::placeholders; namespace { // Used to check correspondence between allocators and deallocators. -enum AllocationFamily { +enum AllocationFamilyKind { AF_None, AF_Malloc, AF_CXXNew, AF_CXXNewArray, AF_IfNameIndex, AF_Alloca, - AF_InnerBuffer + AF_InnerBuffer, + AF_Custom, +}; + +class AllocationFamily { +public: + AllocationFamily(AllocationFamilyKind kind, + std::optional<StringRef> name = std::nullopt) + : _kind(kind), _customName(name) { + assert(kind != AF_Custom || name != std::nullopt); + } + + bool operator==(const AllocationFamily &Other) const { + if (Other.kind() == this->kind()) { + return this->kind() == AF_Custom ? this->_customName == Other._customName + : true; + } else { + return false; + } + } + + bool operator==(const AllocationFamilyKind &kind) { + return this->kind() == kind; + } + + bool operator!=(const AllocationFamilyKind &kind) { return !(*this == kind); } + + std::optional<StringRef> name() const { return _customName; } + AllocationFamilyKind kind() const { return _kind; } + +private: + AllocationFamilyKind _kind; + std::optional<StringRef> _customName; ---------------- steakhal wrote:
I think it should be fine to have these fields as public members, given the complexity of this class. This is basically a std::pair. Feel free to use `struct` instead of `class`. https://github.com/llvm/llvm-project/pull/98941 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits