diff options
-rw-r--r-- | include/llvm/Bitcode/BitstreamReader.h | 4 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitstreamReader.cpp | 17 |
2 files changed, 16 insertions, 5 deletions
diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index 1b29c3e..56a6108 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -343,8 +343,8 @@ public: uint32_t Read(unsigned NumBits) { - assert(NumBits <= 32 && "Cannot return more than 32 bits!"); - if (NumBits == 0) return 0; + assert(NumBits && NumBits <= 32 && + "Cannot return zero or more than 32 bits!"); // If the field is fully contained by CurWord, return it quickly. if (BitsInCurWord >= NumBits) { diff --git a/lib/Bitcode/Reader/BitstreamReader.cpp b/lib/Bitcode/Reader/BitstreamReader.cpp index 85076f3..b133502 100644 --- a/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/lib/Bitcode/Reader/BitstreamReader.cpp @@ -288,9 +288,20 @@ void BitstreamCursor::ReadAbbrevRecord() { } BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); - if (BitCodeAbbrevOp::hasEncodingData(E)) - Abbv->Add(BitCodeAbbrevOp(E, ReadVBR64(5))); - else + if (BitCodeAbbrevOp::hasEncodingData(E)) { + unsigned Data = ReadVBR64(5); + + // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) + // and vbr(0) as a literal zero. This is decoded the same way, and avoids + // a slow path in Read() to have to handle reading zero bits. + if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && + Data == 0) { + Abbv->Add(BitCodeAbbrevOp(0)); + continue; + } + + Abbv->Add(BitCodeAbbrevOp(E, Data)); + } else Abbv->Add(BitCodeAbbrevOp(E)); } CurAbbrevs.push_back(Abbv); |