[ADT] Fix an empty BitVector call getData assert `idx < size()' failed (#65505)

Fixes #65500
This commit is contained in:
Wingrez 2023-09-08 16:23:47 +08:00 committed by GitHub
parent d4c3c2872f
commit 3639d81f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -688,7 +688,7 @@ public:
}
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.

View File

@ -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());