Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions llvm/include/llvm/ADT/Bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ class Bitset {
for (size_t I = 0; I != B.size(); ++I)
Bits[I] = B[I];
} else {
for (size_t I = 0; I != B.size(); ++I) {
unsigned BitsToAssign = NumBits;
for (size_t I = 0; I != B.size() && BitsToAssign; ++I) {
uint64_t Elt = B[I];
Bits[2 * I] = static_cast<uint32_t>(Elt);
Bits[2 * I + 1] = static_cast<uint32_t>(Elt >> 32);
// On a 32-bit system the storage type will be 32-bit, so we may only
// need half of a uint64_t.
for (size_t offset = 0; offset != 2 && BitsToAssign; ++offset) {
Bits[2 * I + offset] = static_cast<uint32_t>(Elt >> (32 * offset));
BitsToAssign = BitsToAssign >= 32 ? BitsToAssign - 32 : 0;
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions llvm/unittests/ADT/BitsetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,41 @@ class TestBitsetUInt64Array : public Bitset<NumBits> {

return true;
}

void verifyStorageSize(size_t elements_64_bit, size_t elements_32_bit) {
if constexpr (sizeof(uintptr_t) == sizeof(uint64_t))
EXPECT_EQ(sizeof(*this), elements_64_bit * sizeof(uintptr_t));
else
EXPECT_EQ(sizeof(*this), elements_32_bit * sizeof(uintptr_t));
}
};

TEST(BitsetTest, Construction) {
std::array<uint64_t, 2> TestVals = {0x123456789abcdef3, 0x1337d3a0b22c24};
TestBitsetUInt64Array<96> Test(TestVals);
EXPECT_TRUE(Test.verifyValue(TestVals));
Test.verifyStorageSize(2, 3);

TestBitsetUInt64Array<65> Test1(TestVals);
EXPECT_TRUE(Test1.verifyValue(TestVals));
Test1.verifyStorageSize(2, 3);

std::array<uint64_t, 1> TestSingleVal = {0x12345678abcdef99};

TestBitsetUInt64Array<64> Test64(TestSingleVal);
EXPECT_TRUE(Test64.verifyValue(TestSingleVal));
Test64.verifyStorageSize(1, 2);

TestBitsetUInt64Array<30> Test30(TestSingleVal);
EXPECT_TRUE(Test30.verifyValue(TestSingleVal));
Test30.verifyStorageSize(1, 1);

TestBitsetUInt64Array<32> Test32(TestSingleVal);
EXPECT_TRUE(Test32.verifyValue(TestSingleVal));
Test32.verifyStorageSize(1, 1);

TestBitsetUInt64Array<33> Test33(TestSingleVal);
EXPECT_TRUE(Test33.verifyValue(TestSingleVal));
Test33.verifyStorageSize(1, 2);
}
} // namespace
Loading