[llvm-commits] [llvm] r41831 - /llvm/trunk/include/llvm/ADT/DenseMap.h
Owen Anderson
resistor at mac.com
Mon Sep 10 20:48:09 PDT 2007
Author: resistor
Date: Mon Sep 10 22:48:08 2007
New Revision: 41831
URL: http://llvm.org/viewvc/llvm-project?rev=41831&view=rev
Log:
Fix non-deterministic behavior in the DenseMap copy constructor.
Modified:
llvm/trunk/include/llvm/ADT/DenseMap.h
Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=41831&r1=41830&r2=41831&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Mon Sep 10 22:48:08 2007
@@ -181,7 +181,7 @@
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 @@
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;
}
More information about the llvm-commits
mailing list