mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-11 05:24:16 +00:00
fix crash in SmallDenseMap copy constructor
Prevent a crash in the SmallDenseMap copy constructor whenever the other map is not in small mode. <rdar://problem/14292693> llvm-svn: 202206
This commit is contained in:
parent
1b07b35205
commit
56ef9a3086
@ -830,7 +830,7 @@ public:
|
||||
Small = true;
|
||||
if (other.getNumBuckets() > InlineBuckets) {
|
||||
Small = false;
|
||||
allocateBuckets(other.getNumBuckets());
|
||||
new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
|
||||
}
|
||||
this->BaseT::copyFrom(other);
|
||||
}
|
||||
|
@ -209,6 +209,34 @@ TYPED_TEST(DenseMapTest, CopyConstructorTest) {
|
||||
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
|
||||
}
|
||||
|
||||
// Test copy constructor method where SmallDenseMap isn't small.
|
||||
TYPED_TEST(DenseMapTest, CopyConstructorNotSmallTest) {
|
||||
for (int Key = 0; Key < 5; ++Key)
|
||||
this->Map[this->getKey(Key)] = this->getValue(Key);
|
||||
TypeParam copyMap(this->Map);
|
||||
|
||||
EXPECT_EQ(5u, copyMap.size());
|
||||
for (int Key = 0; Key < 5; ++Key)
|
||||
EXPECT_EQ(this->getValue(Key), copyMap[this->getKey(Key)]);
|
||||
}
|
||||
|
||||
// Test copying from a default-constructed map.
|
||||
TYPED_TEST(DenseMapTest, CopyConstructorFromDefaultTest) {
|
||||
TypeParam copyMap(this->Map);
|
||||
|
||||
EXPECT_TRUE(copyMap.empty());
|
||||
}
|
||||
|
||||
// Test copying from an empty map where SmallDenseMap isn't small.
|
||||
TYPED_TEST(DenseMapTest, CopyConstructorFromEmptyTest) {
|
||||
for (int Key = 0; Key < 5; ++Key)
|
||||
this->Map[this->getKey(Key)] = this->getValue(Key);
|
||||
this->Map.clear();
|
||||
TypeParam copyMap(this->Map);
|
||||
|
||||
EXPECT_TRUE(copyMap.empty());
|
||||
}
|
||||
|
||||
// Test assignment operator method
|
||||
TYPED_TEST(DenseMapTest, AssignmentTest) {
|
||||
this->Map[this->getKey()] = this->getValue();
|
||||
|
Loading…
Reference in New Issue
Block a user