llvm.org GIT mirror llvm / 9544dc2
Fix non-deterministic behavior in the DenseMap copy constructor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41831 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
1 changed file(s) with 9 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
180180
181181 private:
182182 void CopyFrom(const DenseMap& other) {
183 if (NumEntries != 0) {
183 if (NumBuckets != 0 && !KeyInfoT::isPod()) {
184184 const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
185185 for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
186186 if (P->first != EmptyKey && P->first != TombstoneKey)
196196 delete[] reinterpret_cast(Buckets);
197197 Buckets = reinterpret_cast(new char[sizeof(BucketT) *
198198 other.NumBuckets]);
199 memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
200
199
200 if (KeyInfoT::isPod())
201 memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
202 else
203 for (size_t i = 0; i < other.NumBuckets; ++i) {
204 new (Buckets[i].first) KeyT(other.Buckets[i].first);
205 new (Buckets[i].second) ValueT(other.Buckets[i].second);
206 }
201207 NumBuckets = other.NumBuckets;
202208 }
203209