summaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-07 18:39:49 +0000
committerChris Lattner <sabre@nondot.org>2009-07-07 18:39:49 +0000
commitf5a1edce2370664a439cebdc895c8d559354b0c6 (patch)
tree4071c99f8b6ed3c5673d814852cf87c4b4778ced /include/llvm/Bitcode
parenta9d1f2c559ef4b2549e29288fe6944e68913ba0f (diff)
downloadllvm-f5a1edce2370664a439cebdc895c8d559354b0c6.tar.gz
llvm-f5a1edce2370664a439cebdc895c8d559354b0c6.tar.bz2
llvm-f5a1edce2370664a439cebdc895c8d559354b0c6.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74932 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r--include/llvm/Bitcode/BitstreamReader.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h
index 28249eec0b..83d2350fe8 100644
--- a/include/llvm/Bitcode/BitstreamReader.h
+++ b/include/llvm/Bitcode/BitstreamReader.h
@@ -260,6 +260,7 @@ public:
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 @@ public:
}
}
+ // 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;