[PATCH] D53260: [ADT] Fix a bug in DenseSet's initializer_list constructor.
Lang Hames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 14 12:07:16 PDT 2018
lhames created this revision.
lhames added reviewers: chandlerc, dblaikie.
Herald added subscribers: kristina, dexonsmith.
Without this fix, DenseSet crashes with an assertion if constructed with an
initializer_list whose length is not a power of two.
Repository:
rL LLVM
https://reviews.llvm.org/D53260
Files:
include/llvm/ADT/DenseSet.h
unittests/ADT/DenseSetTest.cpp
Index: unittests/ADT/DenseSetTest.cpp
===================================================================
--- unittests/ADT/DenseSetTest.cpp
+++ unittests/ADT/DenseSetTest.cpp
@@ -80,6 +80,12 @@
EXPECT_EQ(0u, set.count(3));
}
+TYPED_TEST(DenseSetTest, InitializerListWithNonPowerOfTwoLength) {
+ // Make sure the initializer list works even when its length is not a power
+ // of two.
+ TypeParam set({1, 2, 3});
+}
+
TYPED_TEST(DenseSetTest, ConstIteratorComparison) {
TypeParam set({1});
const TypeParam &cset = set;
Index: include/llvm/ADT/DenseSet.h
===================================================================
--- include/llvm/ADT/DenseSet.h
+++ include/llvm/ADT/DenseSet.h
@@ -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 @@
explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}
DenseSetImpl(std::initializer_list<ValueT> Elems)
- : DenseSetImpl(Elems.size()) {
+ : DenseSetImpl(NextPowerOf2(Elems.size())) {
insert(Elems.begin(), Elems.end());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53260.169618.patch
Type: text/x-patch
Size: 1202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181014/86ed74e3/attachment.bin>
More information about the llvm-commits
mailing list