[llvm-commits] [llvm] r74932 - /llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
Chris Lattner
sabre at nondot.org
Tue Jul 7 11:40:11 PDT 2009
Author: lattner
Date: Tue Jul 7 13:39:49 2009
New Revision: 74932
URL: http://llvm.org/viewvc/llvm-project?rev=74932&view=rev
Log:
fix some type confusion in ReadVBR64: "Piece" should be only 32 bits,
not 64, because we read at most 32 bits at a time. OTOH, "Result" must
be 64-bits and insertion into it must be 64-bit clean. Thanks to Ivan
Sorokin for bringing this up.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=74932&r1=74931&r2=74932&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Tue Jul 7 13:39:49 2009
@@ -260,6 +260,7 @@
uint32_t Read(unsigned NumBits) {
+ assert(NumBits <= 32 && "Cannot return more than 32 bits!");
// If the field is fully contained by CurWord, return it quickly.
if (BitsInCurWord >= NumBits) {
uint32_t R = CurWord & ((1U << NumBits)-1);
@@ -322,17 +323,19 @@
}
}
+ // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size. The
+ // chunk size of the VBR must still be <= 32 bits though.
uint64_t ReadVBR64(unsigned NumBits) {
- uint64_t Piece = Read(NumBits);
- if ((Piece & (uint64_t(1) << (NumBits-1))) == 0)
- return Piece;
+ uint32_t Piece = Read(NumBits);
+ if ((Piece & (1U << (NumBits-1))) == 0)
+ return uint64_t(Piece);
uint64_t Result = 0;
unsigned NextBit = 0;
while (1) {
- Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit;
+ Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit;
- if ((Piece & (uint64_t(1) << (NumBits-1))) == 0)
+ if ((Piece & (1U << (NumBits-1))) == 0)
return Result;
NextBit += NumBits-1;
More information about the llvm-commits
mailing list