several bitfixes to JumpToBit
authorChris Lattner <sabre@nondot.org>
Tue, 1 May 2007 05:51:32 +0000 (05:51 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 1 May 2007 05:51:32 +0000 (05:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36616 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/BitstreamReader.h

index 634bc738dfdd71bb5a650965bf09968456750287..8d70f1f7133e990dbb3b47df5d5289af83a17646 100644 (file)
@@ -93,16 +93,19 @@ public:
   
   /// JumpToBit - Reset the stream to the specified bit number.
   void JumpToBit(uint64_t BitNo) {
-    unsigned WordNo = BitNo/32;
+    unsigned ByteNo = (BitNo/8) & ~3;
     unsigned WordBitNo = BitNo & 31;
-    assert(WordNo < (unsigned)(LastChar-FirstChar) && "Invalid location");
+    assert(ByteNo < (unsigned)(LastChar-FirstChar) && "Invalid location");
     
     // Move the cursor to the right word.
-    NextChar = FirstChar+WordNo;
+    NextChar = FirstChar+ByteNo;
     BitsInCurWord = 0;
     
     // Skip over any bits that are already consumed.
-    if (WordBitNo) Read(WordBitNo);
+    if (WordBitNo) {
+      NextChar -= 4;
+      Read(WordBitNo);
+    }
   }
   
   /// GetAbbrevIDWidth - Return the number of bits used to encode an abbrev #.