[PATCH] D77038: Fix bug in BitVector DenseMap hashing
Brad Moody via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 01:02:40 PDT 2020
bmoody created this revision.
bmoody added a reviewer: zturner.
Herald added a subscriber: dexonsmith.
Herald added a project: LLVM.
BitVectors with equal contents but different capacities were getting
different hashes. This also changes the behaviour of BitVector::getData
to only return the in-use words in the allocated array, but it appears that
the hashing code was the only thing using getData.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77038
Files:
llvm/include/llvm/ADT/BitVector.h
llvm/unittests/ADT/BitVectorTest.cpp
Index: llvm/unittests/ADT/BitVectorTest.cpp
===================================================================
--- llvm/unittests/ADT/BitVectorTest.cpp
+++ llvm/unittests/ADT/BitVectorTest.cpp
@@ -1204,4 +1204,22 @@
EXPECT_EQ(true, Set.erase(A));
EXPECT_EQ(0U, Set.size());
}
+
+/// Test that capacity doesn't affect hashing.
+TYPED_TEST(BitVectorTest, DenseMapHashing) {
+ using DMI = DenseMapInfo<TypeParam>;
+ {
+ TypeParam A;
+ A.resize(200);
+ A.set(100);
+
+ TypeParam B;
+ B.resize(200);
+ B.set(100);
+ B.reserve(1000);
+
+ EXPECT_EQ(DMI::getHashValue(A), DMI::getHashValue(B));
+ }
+}
+
} // namespace
Index: llvm/include/llvm/ADT/BitVector.h
===================================================================
--- llvm/include/llvm/ADT/BitVector.h
+++ llvm/include/llvm/ADT/BitVector.h
@@ -759,7 +759,9 @@
}
bool isInvalid() const { return Size == (unsigned)-1; }
- ArrayRef<BitWord> getData() const { return Bits; }
+ ArrayRef<BitWord> getData() const {
+ return Bits.take_front(NumBitWords(size()));
+ }
//===--------------------------------------------------------------------===//
// Portable bit mask operations.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77038.253508.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200330/0448edcc/attachment-0001.bin>
More information about the llvm-commits
mailing list