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
2 changes: 2 additions & 0 deletions llvm/include/llvm/ADT/PackedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class PackedVectorBase<T, BitNum, BitVectorTy, true> {
if (val < 0) {
val = ~val;
Bits.set((Idx * BitNum) + BitNum - 1);
} else {
Bits.reset((Idx * BitNum) + BitNum - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect signed types to be disallowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The author seems to mean to support signed types as far as I can tell from PackedVectorBase.

template <typename T, unsigned BitNum, typename BitVectorTy, bool isSigned>
class PackedVectorBase;

template <typename T, unsigned BitNum, typename BitVectorTy>
class PackedVectorBase<T, BitNum, BitVectorTy, false> {
  :
  :
};

template <typename T, unsigned BitNum, typename BitVectorTy>
class PackedVectorBase<T, BitNum, BitVectorTy, true> {
  :
  :
};

}
assert((val >> (BitNum-1)) == 0 && "value is too big");
for (unsigned i = 0; i != BitNum-1; ++i)
Expand Down
8 changes: 8 additions & 0 deletions llvm/unittests/ADT/PackedVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ TEST(PackedVectorTest, RawBitsSize) {
EXPECT_EQ(12u, Vec.raw_bits().size());
}

TEST(PackedVectorTest, SignedValueOverwrite) {
PackedVector<signed, 4> Vec(1);
Vec[0] = -1;
EXPECT_EQ(-1, Vec[0]);
Vec[0] = 1;
EXPECT_EQ(1, Vec[0]);
}

#ifdef EXPECT_DEBUG_DEATH

TEST(PackedVectorTest, UnsignedValues) {
Expand Down