[llvm] r285785 - Bitcode: Fix short read implementation.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 19:58:47 PDT 2016
Author: pcc
Date: Tue Nov 1 21:58:47 2016
New Revision: 285785
URL: http://llvm.org/viewvc/llvm-project?rev=285785&view=rev
Log:
Bitcode: Fix short read implementation.
We need to zero extend the byte in order to correctly shift it into a
64-bit value.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=285785&r1=285784&r2=285785&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Tue Nov 1 21:58:47 2016
@@ -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;
Modified: llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp?rev=285785&r1=285784&r2=285785&view=diff
==============================================================================
--- llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp (original)
+++ llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp Tue Nov 1 21:58:47 2016
@@ -158,4 +158,13 @@ TEST(BitstreamReaderTest, readRecordWith
}
}
+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
More information about the llvm-commits
mailing list