summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Bitcode/BitstreamReader.h2
-rw-r--r--llvm/unittests/Bitcode/BitstreamReaderTest.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/include/llvm/Bitcode/BitstreamReader.h b/llvm/include/llvm/Bitcode/BitstreamReader.h
index 8808935837a..b258e806e67 100644
--- a/llvm/include/llvm/Bitcode/BitstreamReader.h
+++ b/llvm/include/llvm/Bitcode/BitstreamReader.h
@@ -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;
diff --git a/llvm/unittests/Bitcode/BitstreamReaderTest.cpp b/llvm/unittests/Bitcode/BitstreamReaderTest.cpp
index b5bd4a6fb5a..986023ee3e9 100644
--- a/llvm/unittests/Bitcode/BitstreamReaderTest.cpp
+++ b/llvm/unittests/Bitcode/BitstreamReaderTest.cpp
@@ -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
OpenPOWER on IntegriCloud