[llvm] 3639d81 - [ADT] Fix an empty BitVector call getData assert `idx < size()' failed (#65505)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 8 01:23:51 PDT 2023
Author: Wingrez
Date: 2023-09-08T10:23:47+02:00
New Revision: 3639d81f7e31a65eb7fcfcb2667b5d6c55774579
URL: https://github.com/llvm/llvm-project/commit/3639d81f7e31a65eb7fcfcb2667b5d6c55774579
DIFF: https://github.com/llvm/llvm-project/commit/3639d81f7e31a65eb7fcfcb2667b5d6c55774579.diff
LOG: [ADT] Fix an empty BitVector call getData assert `idx < size()' failed (#65505)
Fixes #65500
Added:
Modified:
llvm/include/llvm/ADT/BitVector.h
llvm/unittests/ADT/BitVectorTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h
index a8847a326753781..e0de1afcc941823 100644
--- a/llvm/include/llvm/ADT/BitVector.h
+++ b/llvm/include/llvm/ADT/BitVector.h
@@ -688,7 +688,7 @@ class BitVector {
}
bool isInvalid() const { return Size == (unsigned)-1; }
- ArrayRef<BitWord> getData() const { return {&Bits[0], Bits.size()}; }
+ ArrayRef<BitWord> getData() const { return {Bits.data(), Bits.size()}; }
//===--------------------------------------------------------------------===//
// Portable bit mask operations.
diff --git a/llvm/unittests/ADT/BitVectorTest.cpp b/llvm/unittests/ADT/BitVectorTest.cpp
index ce043d47b97f1a7..e00e11e4655aa0e 100644
--- a/llvm/unittests/ADT/BitVectorTest.cpp
+++ b/llvm/unittests/ADT/BitVectorTest.cpp
@@ -1134,6 +1134,14 @@ TYPED_TEST(BitVectorTest, EmptyVector) {
testEmpty(E);
}
+/// Make sure calling getData() is legal even on an empty BitVector
+TYPED_TEST(BitVectorTest, EmptyVectorGetData) {
+ BitVector A;
+ testEmpty(A);
+ auto B = A.getData();
+ EXPECT_TRUE(B.empty());
+}
+
TYPED_TEST(BitVectorTest, Iterators) {
TypeParam Filled(10, true);
EXPECT_NE(Filled.set_bits_begin(), Filled.set_bits_end());
More information about the llvm-commits
mailing list