Fix the ValueMap copy constructor. The issue is that the map keys are value
[oota-llvm.git] / include / llvm / ADT / ValueMap.h
index 98e437732584f1ffac2b5e1dfd55d06ed8dd3721..f7560681097812cc2d1da1fe99cf84039785f01a 100644 (file)
@@ -87,7 +87,12 @@ public:
   typedef ValueT mapped_type;
   typedef std::pair<KeyT, ValueT> value_type;
 
   typedef ValueT mapped_type;
   typedef std::pair<KeyT, ValueT> value_type;
 
-  ValueMap(const ValueMap& Other) : Map(Other.Map), Data(Other.Data) {}
+  ValueMap(const ValueMap& Other) : Map(Other.Map), Data(Other.Data) {
+    // Each ValueMapCVH key contains a pointer to the containing ValueMap.
+    // The keys in the new map need to point to the new map, not Other.
+    for (typename MapT::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
+      I->first.Map = this;
+  }
 
   explicit ValueMap(unsigned NumInitBuckets = 64)
     : Map(NumInitBuckets), Data() {}
 
   explicit ValueMap(unsigned NumInitBuckets = 64)
     : Map(NumInitBuckets), Data() {}