[llvm] r208243 - Let OnDiskHashTable call the destructor of its Items.

Nico Weber nicolasweber at gmx.de
Wed May 7 12:55:38 PDT 2014


Author: nico
Date: Wed May  7 14:55:38 2014
New Revision: 208243

URL: http://llvm.org/viewvc/llvm-project?rev=208243&view=rev
Log:
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!

Modified:
    llvm/trunk/include/llvm/Support/OnDiskHashTable.h

Modified: llvm/trunk/include/llvm/Support/OnDiskHashTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/OnDiskHashTable.h?rev=208243&r1=208242&r2=208243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/OnDiskHashTable.h (original)
+++ llvm/trunk/include/llvm/Support/OnDiskHashTable.h Wed May  7 14:55:38 2014
@@ -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 OnDiskCha
         : 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.





More information about the llvm-commits mailing list