diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-05-07 19:55:38 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-05-07 19:55:38 +0000 |
commit | 1ec10c111c2aecfb14a3cb50162b3e4403d4b066 (patch) | |
tree | cfe060b1ce2fddb83b70e986645e7eeac8970c1e | |
parent | b507e6601d23aa37f60b1714f76a8abb00c492d3 (diff) | |
download | llvm-1ec10c111c2aecfb14a3cb50162b3e4403d4b066.tar.gz llvm-1ec10c111c2aecfb14a3cb50162b3e4403d4b066.tar.bz2 llvm-1ec10c111c2aecfb14a3cb50162b3e4403d4b066.tar.xz |
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
-rw-r--r-- | include/llvm/Support/OnDiskHashTable.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/include/llvm/Support/OnDiskHashTable.h b/include/llvm/Support/OnDiskHashTable.h index 2310580bf3..f6d43a4407 100644 --- a/include/llvm/Support/OnDiskHashTable.h +++ b/include/llvm/Support/OnDiskHashTable.h @@ -56,11 +56,6 @@ namespace llvm { /// }; /// \endcode template <typename Info> class OnDiskChainedHashTableGenerator { - typedef typename Info::offset_type offset_type; - offset_type NumBuckets; - offset_type NumEntries; - llvm::BumpPtrAllocator BA; - /// \brief A single item in the hash table. class Item { public: @@ -74,6 +69,11 @@ template <typename Info> class OnDiskChainedHashTableGenerator { : Key(Key), Data(Data), Next(nullptr), Hash(InfoObj.ComputeHash(Key)) {} }; + typedef typename Info::offset_type offset_type; + offset_type NumBuckets; + offset_type NumEntries; + llvm::SpecificBumpPtrAllocator<Item> BA; + /// \brief A linked list of values in a particular hash bucket. class Bucket { public: @@ -129,8 +129,7 @@ public: ++NumEntries; if (4 * NumEntries >= 3 * NumBuckets) resize(NumBuckets * 2); - insert(Buckets, NumBuckets, - new (BA.Allocate<Item>()) Item(Key, Data, InfoObj)); + insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj)); } /// \brief Emit the table to Out, which must not be at offset 0. |