Fix non-deterministic behavior in the DenseMap copy constructor.
authorOwen Anderson <resistor@mac.com>
Tue, 11 Sep 2007 03:48:08 +0000 (03:48 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 11 Sep 2007 03:48:08 +0000 (03:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41831 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DenseMap.h

index 492dd451b2c875e3a24d4ce149059533015a20d1..fe912404cd9a43cdc4bda366589ea02b426ec6b4 100644 (file)
@@ -181,7 +181,7 @@ public:
   
 private:
   void CopyFrom(const DenseMap& other) {
-    if (NumEntries != 0) {
+    if (NumBuckets != 0 && !KeyInfoT::isPod()) {
       const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
       for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
         if (P->first != EmptyKey && P->first != TombstoneKey)
@@ -197,8 +197,14 @@ private:
       delete[] reinterpret_cast<char*>(Buckets);
     Buckets = reinterpret_cast<BucketT*>(new char[sizeof(BucketT) *
                                                   other.NumBuckets]);
-    memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
     
+    if (KeyInfoT::isPod())
+      memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
+    else
+      for (size_t i = 0; i < other.NumBuckets; ++i) {
+        new (Buckets[i].first) KeyT(other.Buckets[i].first);
+        new (Buckets[i].second) ValueT(other.Buckets[i].second);
+      }
     NumBuckets = other.NumBuckets;
   }