[PATCH] D129825: Fix assertion in SmallDenseMap constructor with reserve from non-power-of-2 buckets count
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 10:10:07 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2c84b92346bc: Fix assertion in SmallDenseMap constructor with reserve from non-power-of-2… (authored by dzhidzhoev, committed by dblaikie).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129825/new/
https://reviews.llvm.org/D129825
Files:
llvm/include/llvm/ADT/DenseMap.h
llvm/unittests/ADT/DenseMapTest.cpp
Index: llvm/unittests/ADT/DenseMapTest.cpp
===================================================================
--- llvm/unittests/ADT/DenseMapTest.cpp
+++ llvm/unittests/ADT/DenseMapTest.cpp
@@ -607,6 +607,15 @@
EXPECT_TRUE(map.find(0) == map.end());
}
+TEST(DenseMapCustomTest, SmallDenseMapWithNumBucketsNonPowerOf2) {
+ // Is not power of 2.
+ const unsigned NumInitBuckets = 33;
+ // Power of 2 less then NumInitBuckets.
+ constexpr unsigned InlineBuckets = 4;
+ // Constructor should not trigger assert.
+ SmallDenseMap<int, int, InlineBuckets> map(NumInitBuckets);
+}
+
TEST(DenseMapCustomTest, TryEmplaceTest) {
DenseMap<int, std::unique_ptr<int>> Map;
std::unique_ptr<int> P(new int(2));
Index: llvm/include/llvm/ADT/DenseMap.h
===================================================================
--- llvm/include/llvm/ADT/DenseMap.h
+++ llvm/include/llvm/ADT/DenseMap.h
@@ -907,6 +907,8 @@
public:
explicit SmallDenseMap(unsigned NumInitBuckets = 0) {
+ if (NumInitBuckets > InlineBuckets)
+ NumInitBuckets = NextPowerOf2(NumInitBuckets - 1);
init(NumInitBuckets);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129825.447393.patch
Type: text/x-patch
Size: 1118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/5212f40c/attachment.bin>
More information about the llvm-commits
mailing list