summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2013-02-09 07:07:29 +0000
committerChris Lattner <sabre@nondot.org>2013-02-09 07:07:29 +0000
commit6c29cb3b7a233e7ddd5e48b348078eb2af91473a (patch)
tree0d7e8e001ededd1c7cc9d6ab707be3e62258172e /llvm/lib/Bitcode/Reader/BitstreamReader.cpp
parent1420fda82f7de7ffcab19daf746376811d34430a (diff)
downloadbcm5719-llvm-6c29cb3b7a233e7ddd5e48b348078eb2af91473a.tar.gz
bcm5719-llvm-6c29cb3b7a233e7ddd5e48b348078eb2af91473a.zip
Fix the underlying problem that was causing read(0) to be called: sometimes the
bitcode writer would generate abbrev records saying that the abbrev should be filled with fixed zero-bit bitfields (this happens in the .bc writer when the number of types used in a module is exactly one, since log2(1) == 0). In this case, just handle it as a literal zero. We can't "just fix" the writer without breaking compatibility with existing bc files, so have the abbrev reader do the substitution. Strengthen the assert in read to reject reads of zero bits so we catch such crimes in the future, and remove the special case designed to handle this. llvm-svn: 174801
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitstreamReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitstreamReader.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
index 85076f35020..b1335029a75 100644
--- a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud