diff options
Diffstat (limited to 'llvm/lib/Bitstream/Reader/BitstreamReader.cpp')
-rw-r--r-- | llvm/lib/Bitstream/Reader/BitstreamReader.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp index 28adfe62..751caa2 100644 --- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp +++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp @@ -16,6 +16,10 @@ using namespace llvm; //===----------------------------------------------------------------------===// // BitstreamCursor implementation //===----------------------------------------------------------------------===// +// +static Error error(const char *Message) { + return createStringError(std::errc::illegal_byte_sequence, Message); +} /// Having read the ENTER_SUBBLOCK abbrevid, enter the block. Error BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { @@ -152,7 +156,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) { // Decode the value as we are commanded. switch (EltEnc.getEncoding()) { default: - report_fatal_error("Array element type can't be an Array or a Blob"); + return error("Array element type can't be an Array or a Blob"); case BitCodeAbbrevOp::Fixed: assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize); if (Error Err = @@ -235,7 +239,7 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID, else { if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array || CodeOp.getEncoding() == BitCodeAbbrevOp::Blob) - report_fatal_error("Abbreviation starts with an Array or a Blob"); + return error("Abbreviation starts with an Array or a Blob"); if (Expected<uint64_t> MaybeCode = readAbbreviatedField(*this, CodeOp)) Code = MaybeCode.get(); else @@ -268,16 +272,16 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID, // Get the element encoding. if (i + 2 != e) - report_fatal_error("Array op not second to last"); + return error("Array op not second to last"); const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); if (!EltEnc.isEncoding()) - report_fatal_error( + return error( "Array element type has to be an encoding of a type"); // Read all the elements. switch (EltEnc.getEncoding()) { default: - report_fatal_error("Array element type can't be an Array or a Blob"); + return error("Array element type can't be an Array or a Blob"); case BitCodeAbbrevOp::Fixed: for (; NumElts; --NumElts) if (Expected<SimpleBitstreamCursor::word_t> MaybeVal = @@ -366,6 +370,9 @@ Error BitstreamCursor::ReadAbbrevRecord() { Expected<word_t> MaybeEncoding = Read(3); if (!MaybeEncoding) return MaybeEncoding.takeError(); + if (!BitCodeAbbrevOp::isValidEncoding(MaybeEncoding.get())) + return error("Invalid encoding"); + BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)MaybeEncoding.get(); if (BitCodeAbbrevOp::hasEncodingData(E)) { @@ -385,8 +392,7 @@ Error BitstreamCursor::ReadAbbrevRecord() { if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && Data > MaxChunkSize) - report_fatal_error( - "Fixed or VBR abbrev record with size > MaxChunkData"); + return error("Fixed or VBR abbrev record with size > MaxChunkData"); Abbv->Add(BitCodeAbbrevOp(E, Data)); } else @@ -394,7 +400,7 @@ Error BitstreamCursor::ReadAbbrevRecord() { } if (Abbv->getNumOperandInfos() == 0) - report_fatal_error("Abbrev record with no operands"); + return error("Abbrev record with no operands"); CurAbbrevs.push_back(std::move(Abbv)); return Error::success(); |