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 <br>
<br>(NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31);<br><br>But 'NextChar' is already after the word that we are reading. I propose to fix this by the following patch.<br><br>Index: include/llvm/Bitcode/BitstreamReader.h<br>
===================================================================<br>--- include/llvm/Bitcode/BitstreamReader.h (版本 61317)<br>+++ include/llvm/Bitcode/BitstreamReader.h (工作副本)<br>@@ -114,7 +114,8 @@<br> <br> /// GetCurrentBitNo - Return the bit # of the bit we are reading.<br>
uint64_t GetCurrentBitNo() const {<br>- return (NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31);<br>+ return (NextChar-FirstChar-4)*8 + (BitsInCurWord ? (32-BitsInCurWord) & 31<br>+ : 32);<br>
}<br> <br> /// JumpToBit - Reset the stream to the specified bit number.<br>@@ -130,7 +131,6 @@<br> <br> // Skip over any bits that are already consumed.<br> if (WordBitNo) {<br>- NextChar -= 4;<br>
Read(static_cast<unsigned>(WordBitNo));<br> }<br> }<br><br>