1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Bitcode: Fix short read implementation.

We need to zero extend the byte in order to correctly shift it into a
64-bit value.

llvm-svn: 285785
This commit is contained in:
Peter Collingbourne 2016-11-02 02:58:47 +00:00
parent 932954ed4f
commit a01989574b
2 changed files with 10 additions and 1 deletions

View File

@ -232,7 +232,7 @@ public:
BytesRead = Buf.size() - NextChar;
CurWord = 0;
for (unsigned B = 0; B != BytesRead; ++B)
CurWord |= NextCharPtr[B] << (B * 8);
CurWord |= uint64_t(NextCharPtr[B]) << (B * 8);
}
NextChar += BytesRead;
BitsInCurWord = BytesRead * 8;

View File

@ -158,4 +158,13 @@ TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
}
}
TEST(BitstreamReaderTest, shortRead) {
uint8_t Bytes[] = {8, 7, 6, 5, 4, 3, 2, 1};
for (unsigned I = 1; I != 8; ++I) {
BitstreamReader Reader(ArrayRef<uint8_t>(Bytes, I));
SimpleBitstreamCursor Cursor(Reader);
EXPECT_EQ(8ull, Cursor.Read(8));
}
}
} // end anonymous namespace