Skip to content

Commit 3639d81

Browse files
authored
[ADT] Fix an empty BitVector call getData assert `idx < size()' failed (#65505)
Fixes #65500
1 parent d4c3c28 commit 3639d81

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/include/llvm/ADT/BitVector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ class BitVector {
688688
}
689689
bool isInvalid() const { return Size == (unsigned)-1; }
690690

691-
ArrayRef<BitWord> getData() const { return {&Bits[0], Bits.size()}; }
691+
ArrayRef<BitWord> getData() const { return {Bits.data(), Bits.size()}; }
692692

693693
//===--------------------------------------------------------------------===//
694694
// Portable bit mask operations.

llvm/unittests/ADT/BitVectorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,14 @@ TYPED_TEST(BitVectorTest, EmptyVector) {
11341134
testEmpty(E);
11351135
}
11361136

1137+
/// Make sure calling getData() is legal even on an empty BitVector
1138+
TYPED_TEST(BitVectorTest, EmptyVectorGetData) {
1139+
BitVector A;
1140+
testEmpty(A);
1141+
auto B = A.getData();
1142+
EXPECT_TRUE(B.empty());
1143+
}
1144+
11371145
TYPED_TEST(BitVectorTest, Iterators) {
11381146
TypeParam Filled(10, true);
11391147
EXPECT_NE(Filled.set_bits_begin(), Filled.set_bits_end());

0 commit comments

Comments
 (0)