llvm.org GIT mirror llvm / 1ec10c1
Let OnDiskHashTable call the destructor of its Items. OnDiskHashTable::insert() calls the Item constructor via placement new, but nothing called the destructor. This matters in cases when the Info template parameter has key_type or data_type typedefs that have a destructor, for example like IdentifierIndexWriterTrait in clang's GlobalModuleIndex.cpp. This fixes a 5-year old bug that's been around since the OnDiskHashTable code was added in r64192. Bug found by LSan! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208243 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 6 years ago
1 changed file(s) with 6 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5555 /// };
5656 /// \endcode
5757 template class OnDiskChainedHashTableGenerator {
58 typedef typename Info::offset_type offset_type;
59 offset_type NumBuckets;
60 offset_type NumEntries;
61 llvm::BumpPtrAllocator BA;
62
6358 /// \brief A single item in the hash table.
6459 class Item {
6560 public:
7267 Info &InfoObj)
7368 : Key(Key), Data(Data), Next(nullptr), Hash(InfoObj.ComputeHash(Key)) {}
7469 };
70
71 typedef typename Info::offset_type offset_type;
72 offset_type NumBuckets;
73 offset_type NumEntries;
74 llvm::SpecificBumpPtrAllocator BA;
7575
7676 /// \brief A linked list of values in a particular hash bucket.
7777 class Bucket {
128128 ++NumEntries;
129129 if (4 * NumEntries >= 3 * NumBuckets)
130130 resize(NumBuckets * 2);
131 insert(Buckets, NumBuckets,
132 new (BA.Allocate()) Item(Key, Data, InfoObj));
131 insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj));
133132 }
134133
135134 /// \brief Emit the table to Out, which must not be at offset 0.