summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/ADT/ValueMap.h7
-rw-r--r--unittests/ADT/ValueMapTest.cpp9
2 files changed, 15 insertions, 1 deletions
diff --git a/include/llvm/ADT/ValueMap.h b/include/llvm/ADT/ValueMap.h
index 98e4377325..f756068109 100644
--- a/include/llvm/ADT/ValueMap.h
+++ b/include/llvm/ADT/ValueMap.h
@@ -87,7 +87,12 @@ public:
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() {}
diff --git a/unittests/ADT/ValueMapTest.cpp b/unittests/ADT/ValueMapTest.cpp
index 152e8eaaf1..ff7c3b55b7 100644
--- a/unittests/ADT/ValueMapTest.cpp
+++ b/unittests/ADT/ValueMapTest.cpp
@@ -39,6 +39,15 @@ protected:
typedef ::testing::Types<Value, Instruction, const Instruction> KeyTypes;
TYPED_TEST_CASE(ValueMapTest, KeyTypes);
+TYPED_TEST(ValueMapTest, CopyConstructor) {
+ ValueMap<TypeParam*, int> VM1;
+ VM1[this->AddV.get()] = 7;
+ ValueMap<TypeParam*, int> VM2(VM1);
+ this->AddV.reset();
+ EXPECT_TRUE(VM1.empty());
+ EXPECT_TRUE(VM2.empty());
+}
+
TYPED_TEST(ValueMapTest, Null) {
ValueMap<TypeParam*, int> VM1;
VM1[NULL] = 7;