From 8014c7f1f3b2509b4c5904a286ffa49dc4bfbfae Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 11 Sep 2007 03:48:08 +0000 Subject: [PATCH] Fix non-deterministic behavior in the DenseMap copy constructor. llvm-svn: 41831 --- include/llvm/ADT/DenseMap.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 492dd451b2c..fe912404cd9 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -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(Buckets); Buckets = reinterpret_cast(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; }