[cfe-dev] BitstreamReader::GetCurrentBitNo() counterintuitive

Zhongxing Xu xuzhongxing at gmail.com
Tue Dec 23 00:36:53 PST 2008


As the comments said, BitstreamReader::GetCurrentBitNo() should return the
bit # of the bit we are reading. But the current implementation actually
return 4 more bytes than the bit we are reading. It calculate the bit number
by

(NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31);

But 'NextChar' is already after the word that we are reading. I propose to
fix this by the following patch.

Index: include/llvm/Bitcode/BitstreamReader.h
===================================================================
--- include/llvm/Bitcode/BitstreamReader.h    (版本 61317)
+++ include/llvm/Bitcode/BitstreamReader.h    (工作副本)
@@ -114,7 +114,8 @@

   /// GetCurrentBitNo - Return the bit # of the bit we are reading.
   uint64_t GetCurrentBitNo() const {
-    return (NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31);
+    return (NextChar-FirstChar-4)*8 + (BitsInCurWord ? (32-BitsInCurWord) &
31
+                                                     : 32);
   }

   /// JumpToBit - Reset the stream to the specified bit number.
@@ -130,7 +131,6 @@

     // Skip over any bits that are already consumed.
     if (WordBitNo) {
-      NextChar -= 4;
       Read(static_cast<unsigned>(WordBitNo));
     }
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081223/123ff77d/attachment.html>


More information about the cfe-dev mailing list