1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[ADT] Fix a bug in DenseSet's initializer_list constructor.

Without this fix, DenseSet crashes with an assertion if constructed with an
initializer_list whose length is not a power of two.

llvm-svn: 344542
This commit is contained in:
Lang Hames 2018-10-15 18:34:36 +00:00
parent bab339b613
commit e1e0662c18
2 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/type_traits.h"
#include <algorithm>
#include <cstddef>
@ -67,7 +68,7 @@ public:
explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}
DenseSetImpl(std::initializer_list<ValueT> Elems)
: DenseSetImpl(Elems.size()) {
: DenseSetImpl(PowerOf2Ceil(Elems.size())) {
insert(Elems.begin(), Elems.end());
}

View File

@ -80,6 +80,14 @@ TYPED_TEST(DenseSetTest, InitializerList) {
EXPECT_EQ(0u, set.count(3));
}
TYPED_TEST(DenseSetTest, InitializerListWithNonPowerOfTwoLength) {
TypeParam set({1, 2, 3});
EXPECT_EQ(3u, set.size());
EXPECT_EQ(1u, set.count(1));
EXPECT_EQ(1u, set.count(2));
EXPECT_EQ(1u, set.count(3));
}
TYPED_TEST(DenseSetTest, ConstIteratorComparison) {
TypeParam set({1});
const TypeParam &cset = set;