mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Fix bug in SmallBitVector::find_next_unset
Summary: find_next_unset was returning size() instead of -1 in small-mode, when no unset bits are found. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D77985
This commit is contained in:
parent
73eaffd109
commit
73814f2efb
@ -287,11 +287,11 @@ public:
|
||||
/// Returns -1 if the next unset bit is not found.
|
||||
int find_next_unset(unsigned Prev) const {
|
||||
if (isSmall()) {
|
||||
++Prev;
|
||||
uintptr_t Bits = getSmallBits();
|
||||
// Mask in previous bits.
|
||||
uintptr_t Mask = (uintptr_t(1) << Prev) - 1;
|
||||
Bits |= Mask;
|
||||
Bits |= (uintptr_t(1) << (Prev + 1)) - 1;
|
||||
// Mask in unused bits.
|
||||
Bits |= ~uintptr_t(0) << getSmallSize();
|
||||
|
||||
if (Bits == ~uintptr_t(0) || Prev + 1 >= getSmallSize())
|
||||
return -1;
|
||||
|
@ -297,6 +297,18 @@ TYPED_TEST(BitVectorTest, SimpleFindOpsSingleWord) {
|
||||
EXPECT_EQ(-1, A.find_last_unset());
|
||||
|
||||
A.resize(20);
|
||||
ASSERT_TRUE(SmallBitVectorIsSmallMode(A));
|
||||
EXPECT_EQ(-1, A.find_first());
|
||||
EXPECT_EQ(-1, A.find_last());
|
||||
EXPECT_EQ(-1, A.find_next(5));
|
||||
EXPECT_EQ(-1, A.find_next(19));
|
||||
EXPECT_EQ(-1, A.find_prev(5));
|
||||
EXPECT_EQ(-1, A.find_prev(20));
|
||||
EXPECT_EQ(0, A.find_first_unset());
|
||||
EXPECT_EQ(19, A.find_last_unset());
|
||||
EXPECT_EQ(6, A.find_next_unset(5));
|
||||
EXPECT_EQ(-1, A.find_next_unset(19));
|
||||
|
||||
A.set(3);
|
||||
A.set(4);
|
||||
A.set(16);
|
||||
@ -319,6 +331,19 @@ TYPED_TEST(BitVectorTest, SimpleFindOpsSingleWord) {
|
||||
EXPECT_EQ(5, A.find_next_unset(4));
|
||||
EXPECT_EQ(13, A.find_next_unset(12));
|
||||
EXPECT_EQ(17, A.find_next_unset(15));
|
||||
|
||||
A.set();
|
||||
ASSERT_TRUE(SmallBitVectorIsSmallMode(A));
|
||||
EXPECT_EQ(0, A.find_first());
|
||||
EXPECT_EQ(19, A.find_last());
|
||||
EXPECT_EQ(6, A.find_next(5));
|
||||
EXPECT_EQ(-1, A.find_next(19));
|
||||
EXPECT_EQ(4, A.find_prev(5));
|
||||
EXPECT_EQ(19, A.find_prev(20));
|
||||
EXPECT_EQ(-1, A.find_first_unset());
|
||||
EXPECT_EQ(-1, A.find_last_unset());
|
||||
EXPECT_EQ(-1, A.find_next_unset(5));
|
||||
EXPECT_EQ(-1, A.find_next_unset(19));
|
||||
}
|
||||
|
||||
TEST(BitVectorTest, FindInRangeMultiWord) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user