[patch] Use the DiagnosticHandler to print diagnostics when reading bitcode.
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Jan 9 09:41:00 PST 2015
> On 2015-Jan-09, at 09:35, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
>
>>
>> On 2015-Jan-09, at 08:28, Rafael EspĂndola <rafael.espindola at gmail.com> wrote:
>>
>> Currently the bitcode reading interface uses std::error_code to report
>> an error to the callers and it is the callers job to print
>> diagnostics.
>>
>> This is not ideal for error handling or diagnostic reporting:
>>
>> * For error handling, all that the callers care about is 3 possibilities:
>> * It worked
>> * The bitcode file is corrupted/invalid.
>> * The file is not bitcode at all.
>>
>> * For diagnostic, it is user friendly to include far more information
>> about the invalid case so the user can find out what is wrong with the
>> bitcode file. This comes up for example when a developer introduces a
>> bug while extending the format.
>>
>> The compromise we have currently is to have a lot of error codes.
>>
>> With this patch we use the DiagnosticHandler to communicate with the
>> human and std::error_code to communicate with the caller.
>>
>> This allows us to have far fewer error codes and adds the
>> infrastructure to print better diagnostics. This is so because the
>> diagnostics are printed when the issue is found. The code that
>> detected the problem in alive in the stack and can pass down as much
>> context as needed. As an example the patch updates
>> test/Bitcode/invalid.ll.
>>
>> Using a DiagnosticHandler also moves the fatal/non-fatal error
>> decision to the caller. A simple one like llvm-dis can just use fatal
>> errors. The gold plugin needs a bit more complex treatment because of
>> being passed non-bitcode files. An hypothetical interactive tool would
>> make all bitcode errors non-fatal.
>>
>> Cheers,
>> Rafael
>> <t.patch>
>
> I like this direction, but you seem to have dropped a lot of specificity
> from the error messages. Is this intentional? Why?
>
> (See below for some examples.)
>
Also, it doesn't look like you've set error messages to go back through
libLTO (i.e., `lto_get_error_message()`).
>> diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h
>> index 9a30fb4..a631bbb 100644
>> --- a/include/llvm/Bitcode/ReaderWriter.h
>> +++ b/include/llvm/Bitcode/ReaderWriter.h
>> @@ -14,6 +14,7 @@
>> #ifndef LLVM_BITCODE_READERWRITER_H
>> #define LLVM_BITCODE_READERWRITER_H
>>
>> +#include "llvm/IR/DiagnosticInfo.h"
>> #include "llvm/Support/ErrorOr.h"
>> #include "llvm/Support/MemoryBuffer.h"
>> #include <memory>
>> @@ -138,32 +139,26 @@ namespace llvm {
>> }
>>
>> const std::error_category &BitcodeErrorCategory();
>> - enum class BitcodeError {
>> - ConflictingMETADATA_KINDRecords,
>> - CouldNotFindFunctionInStream,
>> - ExpectedConstant,
>> - InsufficientFunctionProtos,
>> - InvalidBitcodeSignature,
>> - InvalidBitcodeWrapperHeader,
>> - InvalidConstantReference,
>> - InvalidID, // A read identifier is not found in the table it should be in.
>> - InvalidInstructionWithNoBB,
>> - InvalidRecord, // A read record doesn't have the expected size or structure
>> - InvalidTypeForValue, // Type read OK, but is invalid for its use
>> - InvalidTYPETable,
>> - InvalidType, // We were unable to read a type
>> - MalformedBlock, // We are unable to advance in the stream.
>> - MalformedGlobalInitializerSet,
>> - InvalidMultipleBlocks, // We found multiple blocks of a kind that should
>> - // have only one
>> - NeverResolvedValueFoundInFunction,
>> - NeverResolvedFunctionFromBlockAddress,
>> - InvalidValue // Invalid version, inst number, attr number, etc
>> - };
>> + enum class BitcodeError { InvalidBitcodeSignature, CorrupteddBitcode };
>
> s/CorrupteddBitcode/CorruptedBitcode/g
>
>> inline std::error_code make_error_code(BitcodeError E) {
>> return std::error_code(static_cast<int>(E), BitcodeErrorCategory());
>> }
>>
>> + class BitcodeDiagnosticInfo : public DiagnosticInfo {
>> + const Twine &Msg;
>> + std::error_code EC;
>> +
>> + public:
>> + BitcodeDiagnosticInfo(std::error_code EC, DiagnosticSeverity Severity,
>> + const Twine &Msg);
>> + void print(DiagnosticPrinter &DP) const override;
>> + std::error_code getError() const { return EC; };
>> +
>> + static bool classof(const DiagnosticInfo *DI) {
>> + return DI->getKind() == DK_Bitcode;
>> + }
>> + };
>> +
>> } // End llvm namespace
>>
>> namespace std {
>> diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h
>> index b592f89..456901d 100644
>> --- a/include/llvm/IR/DiagnosticInfo.h
>> +++ b/include/llvm/IR/DiagnosticInfo.h
>> @@ -45,6 +45,7 @@ enum DiagnosticSeverity {
>> /// \brief Defines the different supported kind of a diagnostic.
>> /// This enum should be extended with a new ID for each added concrete subclass.
>> enum DiagnosticKind {
>> + DK_Bitcode,
>> DK_InlineAsm,
>> DK_StackSize,
>> DK_Linker,
>> diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
>> index 9a8ec63..bec35eb 100644
>> --- a/lib/Bitcode/Reader/BitcodeReader.cpp
>> +++ b/lib/Bitcode/Reader/BitcodeReader.cpp
>> @@ -15,6 +15,7 @@
>> #include "llvm/IR/AutoUpgrade.h"
>> #include "llvm/IR/Constants.h"
>> #include "llvm/IR/DerivedTypes.h"
>> +#include "llvm/IR/DiagnosticPrinter.h"
>> #include "llvm/IR/InlineAsm.h"
>> #include "llvm/IR/IntrinsicInst.h"
>> #include "llvm/IR/LLVMContext.h"
>> @@ -33,6 +34,32 @@ enum {
>> SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex
>> };
>>
>> +BitcodeDiagnosticInfo::BitcodeDiagnosticInfo(std::error_code EC,
>> + DiagnosticSeverity Severity,
>> + const Twine &Msg)
>> + : DiagnosticInfo(DK_Bitcode, Severity), Msg(Msg), EC(EC) {}
>> +
>> +void BitcodeDiagnosticInfo::print(DiagnosticPrinter &DP) const { DP << Msg; }
>> +
>> +static std::error_code Error(LLVMContext &Context, std::error_code EC,
>> + const Twine &Message) {
>> + BitcodeDiagnosticInfo DI(EC, DS_Error, Message);
>> + Context.diagnose(DI);
>> + return EC;
>> +}
>> +
>> +static std::error_code Error(LLVMContext &Context, std::error_code EC) {
>> + return Error(Context, EC, EC.message());
>> +}
>> +
>> +std::error_code BitcodeReader::Error(BitcodeError E, const Twine &Message) {
>> + return ::Error(Context, make_error_code(E), Message);
>> +}
>> +
>> +std::error_code BitcodeReader::Error(BitcodeError E) {
>> + return ::Error(Context, make_error_code(E));
>> +}
>> +
>> std::error_code BitcodeReader::materializeForwardReferencedFunctions() {
>> if (WillMaterializeAllForwardRefs)
>> return std::error_code();
>> @@ -53,7 +80,7 @@ std::error_code BitcodeReader::materializeForwardReferencedFunctions() {
>> // isn't a trivial way to check if a function will have a body without a
>> // linear search through FunctionsWithBodies, so just check it here.
>> if (!F->isMaterializable())
>> - return Error(BitcodeError::NeverResolvedFunctionFromBlockAddress);
>> + return Error(BitcodeError::CorrupteddBitcode);
>
> Should this retain the old error message?
>
>>
>> // Try to materialize F.
>> if (std::error_code EC = materialize(F))
>> @@ -560,10 +587,10 @@ static void decodeLLVMAttributesForBitcode(AttrBuilder &B,
>>
>> std::error_code BitcodeReader::ParseAttributeBlock() {
>> if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (!MAttributes.empty())
>> - return Error(BitcodeError::InvalidMultipleBlocks);
>> + return Error(BitcodeError::CorrupteddBitcode);
>
> Same question here -- why remove the specific error message?
>
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -576,7 +603,7 @@ std::error_code BitcodeReader::ParseAttributeBlock() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>
> Is it useful to distinguish between MalformedBlock vs. InvalidRecord?
>
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>> case BitstreamEntry::Record:
>> @@ -592,7 +619,7 @@ std::error_code BitcodeReader::ParseAttributeBlock() {
>> case bitc::PARAMATTR_CODE_ENTRY_OLD: { // ENTRY: [paramidx0, attr0, ...]
>> // FIXME: Remove in 4.0.
>> if (Record.size() & 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
>> AttrBuilder B;
>> @@ -710,16 +737,17 @@ std::error_code BitcodeReader::ParseAttrKind(uint64_t Code,
>> Attribute::AttrKind *Kind) {
>> *Kind = GetAttrFromCode(Code);
>> if (*Kind == Attribute::None)
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode,
>> + "Unknown attribute kind (" + Twine(Code) + ")");
>> return std::error_code();
>> }
>>
>> std::error_code BitcodeReader::ParseAttributeGroupBlock() {
>> if (Stream.EnterSubBlock(bitc::PARAMATTR_GROUP_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (!MAttributeGroups.empty())
>> - return Error(BitcodeError::InvalidMultipleBlocks);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -730,7 +758,7 @@ std::error_code BitcodeReader::ParseAttributeGroupBlock() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>> case BitstreamEntry::Record:
>> @@ -745,7 +773,7 @@ std::error_code BitcodeReader::ParseAttributeGroupBlock() {
>> break;
>> case bitc::PARAMATTR_GRP_CODE_ENTRY: { // ENTRY: [grpid, idx, a0, a1, ...]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> uint64_t GrpID = Record[0];
>> uint64_t Idx = Record[1]; // Index of the object this attribute refers to.
>> @@ -800,14 +828,14 @@ std::error_code BitcodeReader::ParseAttributeGroupBlock() {
>>
>> std::error_code BitcodeReader::ParseTypeTable() {
>> if (Stream.EnterSubBlock(bitc::TYPE_BLOCK_ID_NEW))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> return ParseTypeTableBody();
>> }
>>
>> std::error_code BitcodeReader::ParseTypeTableBody() {
>> if (!TypeList.empty())
>> - return Error(BitcodeError::InvalidMultipleBlocks);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>> unsigned NumRecords = 0;
>> @@ -821,10 +849,10 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> if (NumRecords != TypeList.size())
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> return std::error_code();
>> case BitstreamEntry::Record:
>> // The interesting case.
>> @@ -836,12 +864,12 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> Type *ResultTy = nullptr;
>> switch (Stream.readRecord(Entry.ID, Record)) {
>> default:
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case bitc::TYPE_CODE_NUMENTRY: // TYPE_CODE_NUMENTRY: [numentries]
>> // TYPE_CODE_NUMENTRY contains a count of the number of types in the
>> // type list. This allows us to reserve space.
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> TypeList.resize(Record[0]);
>> continue;
>> case bitc::TYPE_CODE_VOID: // VOID
>> @@ -876,20 +904,20 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> break;
>> case bitc::TYPE_CODE_INTEGER: // INTEGER: [width]
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> ResultTy = IntegerType::get(Context, Record[0]);
>> break;
>> case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
>> // [pointee type, address space]
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned AddressSpace = 0;
>> if (Record.size() == 2)
>> AddressSpace = Record[1];
>> ResultTy = getTypeByID(Record[0]);
>> if (!ResultTy)
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>
> Same questions here. Why isn't it useful to know the type is invalid (or the
> value is invalid)? (And if it is useful, maybe include the ids as well.)
>
>> ResultTy = PointerType::get(ResultTy, AddressSpace);
>> break;
>> }
>> @@ -897,7 +925,7 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> // FIXME: attrid is dead, remove it in LLVM 4.0
>> // FUNCTION: [vararg, attrid, retty, paramty x N]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SmallVector<Type*, 8> ArgTys;
>> for (unsigned i = 3, e = Record.size(); i != e; ++i) {
>> if (Type *T = getTypeByID(Record[i]))
>> @@ -908,7 +936,7 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>>
>> ResultTy = getTypeByID(Record[2]);
>> if (!ResultTy || ArgTys.size() < Record.size()-3)
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
>> break;
>> @@ -916,7 +944,7 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> case bitc::TYPE_CODE_FUNCTION: {
>> // FUNCTION: [vararg, retty, paramty x N]
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SmallVector<Type*, 8> ArgTys;
>> for (unsigned i = 2, e = Record.size(); i != e; ++i) {
>> if (Type *T = getTypeByID(Record[i]))
>> @@ -927,14 +955,14 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>>
>> ResultTy = getTypeByID(Record[1]);
>> if (!ResultTy || ArgTys.size() < Record.size()-2)
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
>> break;
>> }
>> case bitc::TYPE_CODE_STRUCT_ANON: { // STRUCT: [ispacked, eltty x N]
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SmallVector<Type*, 8> EltTys;
>> for (unsigned i = 1, e = Record.size(); i != e; ++i) {
>> if (Type *T = getTypeByID(Record[i]))
>> @@ -943,21 +971,21 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> break;
>> }
>> if (EltTys.size() != Record.size()-1)
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> ResultTy = StructType::get(Context, EltTys, Record[0]);
>> break;
>> }
>> case bitc::TYPE_CODE_STRUCT_NAME: // STRUCT_NAME: [strchr x N]
>> if (ConvertToString(Record, 0, TypeName))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> continue;
>>
>> case bitc::TYPE_CODE_STRUCT_NAMED: { // STRUCT: [ispacked, eltty x N]
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (NumRecords >= TypeList.size())
>> - return Error(BitcodeError::InvalidTYPETable);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Check to see if this was forward referenced, if so fill in the temp.
>> StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
>> @@ -976,17 +1004,17 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> break;
>> }
>> if (EltTys.size() != Record.size()-1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Res->setBody(EltTys, Record[0]);
>> ResultTy = Res;
>> break;
>> }
>> case bitc::TYPE_CODE_OPAQUE: { // OPAQUE: []
>> if (Record.size() != 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (NumRecords >= TypeList.size())
>> - return Error(BitcodeError::InvalidTYPETable);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Check to see if this was forward referenced, if so fill in the temp.
>> StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
>> @@ -1001,24 +1029,24 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>> }
>> case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if ((ResultTy = getTypeByID(Record[1])))
>> ResultTy = ArrayType::get(ResultTy, Record[0]);
>> else
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if ((ResultTy = getTypeByID(Record[1])))
>> ResultTy = VectorType::get(ResultTy, Record[0]);
>> else
>> - return Error(BitcodeError::InvalidType);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> }
>>
>> if (NumRecords >= TypeList.size())
>> - return Error(BitcodeError::InvalidTYPETable);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> assert(ResultTy && "Didn't read a type?");
>> assert(!TypeList[NumRecords] && "Already read type?");
>> TypeList[NumRecords++] = ResultTy;
>> @@ -1027,7 +1055,7 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
>>
>> std::error_code BitcodeReader::ParseValueSymbolTable() {
>> if (Stream.EnterSubBlock(bitc::VALUE_SYMTAB_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -1039,7 +1067,7 @@ std::error_code BitcodeReader::ParseValueSymbolTable() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>> case BitstreamEntry::Record:
>> @@ -1054,10 +1082,10 @@ std::error_code BitcodeReader::ParseValueSymbolTable() {
>> break;
>> case bitc::VST_CODE_ENTRY: { // VST_ENTRY: [valueid, namechar x N]
>> if (ConvertToString(Record, 1, ValueName))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned ValueID = Record[0];
>> if (ValueID >= ValueList.size() || !ValueList[ValueID])
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Value *V = ValueList[ValueID];
>>
>> V->setName(StringRef(ValueName.data(), ValueName.size()));
>> @@ -1066,10 +1094,10 @@ std::error_code BitcodeReader::ParseValueSymbolTable() {
>> }
>> case bitc::VST_CODE_BBENTRY: {
>> if (ConvertToString(Record, 1, ValueName))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> BasicBlock *BB = getBasicBlock(Record[0]);
>> if (!BB)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> BB->setName(StringRef(ValueName.data(), ValueName.size()));
>> ValueName.clear();
>> @@ -1083,7 +1111,7 @@ std::error_code BitcodeReader::ParseMetadata() {
>> unsigned NextMDValueNo = MDValueList.size();
>>
>> if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -1094,7 +1122,7 @@ std::error_code BitcodeReader::ParseMetadata() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> MDValueList.tryToResolveCycles();
>> return std::error_code();
>> @@ -1126,7 +1154,7 @@ std::error_code BitcodeReader::ParseMetadata() {
>> for (unsigned i = 0; i != Size; ++i) {
>> MDNode *MD = dyn_cast_or_null<MDNode>(MDValueList.getValueFwdRef(Record[i]));
>> if (!MD)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> NMD->addOperand(MD);
>> }
>> break;
>> @@ -1136,7 +1164,7 @@ std::error_code BitcodeReader::ParseMetadata() {
>> // This is a LocalAsMetadata record, the only type of function-local
>> // metadata.
>> if (Record.size() % 2 == 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // If this isn't a LocalAsMetadata record, we're dropping it. This used
>> // to be legal, but there's no upgrade path.
>> @@ -1162,14 +1190,14 @@ std::error_code BitcodeReader::ParseMetadata() {
>> case bitc::METADATA_OLD_NODE: {
>> // FIXME: Remove in 4.0.
>> if (Record.size() % 2 == 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> unsigned Size = Record.size();
>> SmallVector<Metadata *, 8> Elts;
>> for (unsigned i = 0; i != Size; i += 2) {
>> Type *Ty = getTypeByID(Record[i]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (Ty->isMetadataTy())
>> Elts.push_back(MDValueList.getValueFwdRef(Record[i+1]));
>> else if (!Ty->isVoidTy()) {
>> @@ -1186,11 +1214,11 @@ std::error_code BitcodeReader::ParseMetadata() {
>> }
>> case bitc::METADATA_VALUE: {
>> if (Record.size() != 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Type *Ty = getTypeByID(Record[0]);
>> if (Ty->isMetadataTy() || Ty->isVoidTy())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> MDValueList.AssignValue(
>> ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)),
>> @@ -1219,14 +1247,14 @@ std::error_code BitcodeReader::ParseMetadata() {
>> }
>> case bitc::METADATA_KIND: {
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> unsigned Kind = Record[0];
>> SmallString<8> Name(Record.begin()+1, Record.end());
>>
>> unsigned NewKind = TheModule->getMDKindID(Name.str());
>> if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
>> - return Error(BitcodeError::ConflictingMETADATA_KINDRecords);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> }
>> }
>> @@ -1266,7 +1294,7 @@ std::error_code BitcodeReader::ResolveGlobalAndAliasInits() {
>> if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
>> GlobalInitWorklist.back().first->setInitializer(C);
>> else
>> - return Error(BitcodeError::ExpectedConstant);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> GlobalInitWorklist.pop_back();
>> }
>> @@ -1279,7 +1307,7 @@ std::error_code BitcodeReader::ResolveGlobalAndAliasInits() {
>> if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
>> AliasInitWorklist.back().first->setAliasee(C);
>> else
>> - return Error(BitcodeError::ExpectedConstant);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> AliasInitWorklist.pop_back();
>> }
>> @@ -1292,7 +1320,7 @@ std::error_code BitcodeReader::ResolveGlobalAndAliasInits() {
>> if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
>> FunctionPrefixWorklist.back().first->setPrefixData(C);
>> else
>> - return Error(BitcodeError::ExpectedConstant);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> FunctionPrefixWorklist.pop_back();
>> }
>> @@ -1305,7 +1333,7 @@ std::error_code BitcodeReader::ResolveGlobalAndAliasInits() {
>> if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
>> FunctionPrologueWorklist.back().first->setPrologueData(C);
>> else
>> - return Error(BitcodeError::ExpectedConstant);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> FunctionPrologueWorklist.pop_back();
>> }
>> @@ -1323,7 +1351,7 @@ static APInt ReadWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits) {
>>
>> std::error_code BitcodeReader::ParseConstants() {
>> if (Stream.EnterSubBlock(bitc::CONSTANTS_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -1336,10 +1364,10 @@ std::error_code BitcodeReader::ParseConstants() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> if (NextCstNo != ValueList.size())
>> - return Error(BitcodeError::InvalidConstantReference);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Once all the constants have been read, go through and resolve forward
>> // references.
>> @@ -1361,9 +1389,9 @@ std::error_code BitcodeReader::ParseConstants() {
>> break;
>> case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid]
>> if (Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (Record[0] >= TypeList.size() || !TypeList[Record[0]])
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> CurTy = TypeList[Record[0]];
>> continue; // Skip the ValueList manipulation.
>> case bitc::CST_CODE_NULL: // NULL
>> @@ -1371,12 +1399,12 @@ std::error_code BitcodeReader::ParseConstants() {
>> break;
>> case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
>> if (!CurTy->isIntegerTy() || Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> V = ConstantInt::get(CurTy, decodeSignRotatedValue(Record[0]));
>> break;
>> case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval]
>> if (!CurTy->isIntegerTy() || Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> APInt VInt = ReadWideAPInt(Record,
>> cast<IntegerType>(CurTy)->getBitWidth());
>> @@ -1386,7 +1414,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
>> if (Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (CurTy->isHalfTy())
>> V = ConstantFP::get(Context, APFloat(APFloat::IEEEhalf,
>> APInt(16, (uint16_t)Record[0])));
>> @@ -1416,7 +1444,7 @@ std::error_code BitcodeReader::ParseConstants() {
>>
>> case bitc::CST_CODE_AGGREGATE: {// AGGREGATE: [n x value number]
>> if (Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> unsigned Size = Record.size();
>> SmallVector<Constant*, 16> Elts;
>> @@ -1444,7 +1472,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> case bitc::CST_CODE_STRING: // STRING: [values]
>> case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
>> if (Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallString<16> Elts(Record.begin(), Record.end());
>> V = ConstantDataArray::getString(Context, Elts,
>> @@ -1453,7 +1481,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_DATA: {// DATA: [n x value]
>> if (Record.empty())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Type *EltTy = cast<SequentialType>(CurTy)->getElementType();
>> unsigned Size = Record.size();
>> @@ -1498,14 +1526,14 @@ std::error_code BitcodeReader::ParseConstants() {
>> else
>> V = ConstantDataArray::get(Context, Elts);
>> } else {
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> break;
>> }
>>
>> case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
>> if (Opc < 0) {
>> V = UndefValue::get(CurTy); // Unknown binop.
>> @@ -1536,14 +1564,14 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_CE_CAST: { // CE_CAST: [opcode, opty, opval]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> int Opc = GetDecodedCastOpcode(Record[0]);
>> if (Opc < 0) {
>> V = UndefValue::get(CurTy); // Unknown cast.
>> } else {
>> Type *OpTy = getTypeByID(Record[1]);
>> if (!OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
>> V = UpgradeBitCastExpr(Opc, Op, CurTy);
>> if (!V) V = ConstantExpr::getCast(Opc, Op, CurTy);
>> @@ -1553,12 +1581,12 @@ std::error_code BitcodeReader::ParseConstants() {
>> case bitc::CST_CODE_CE_INBOUNDS_GEP:
>> case bitc::CST_CODE_CE_GEP: { // CE_GEP: [n x operands]
>> if (Record.size() & 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SmallVector<Constant*, 16> Elts;
>> for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
>> Type *ElTy = getTypeByID(Record[i]);
>> if (!ElTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
>> }
>> ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
>> @@ -1569,7 +1597,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_CE_SELECT: { // CE_SELECT: [opval#, opval#, opval#]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Type *SelectorTy = Type::getInt1Ty(Context);
>>
>> @@ -1588,22 +1616,22 @@ std::error_code BitcodeReader::ParseConstants() {
>> case bitc::CST_CODE_CE_EXTRACTELT
>> : { // CE_EXTRACTELT: [opty, opval, opty, opval]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> VectorType *OpTy =
>> dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
>> if (!OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
>> Constant *Op1 = nullptr;
>> if (Record.size() == 4) {
>> Type *IdxTy = getTypeByID(Record[2]);
>> if (!IdxTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Op1 = ValueList.getConstantFwdRef(Record[3], IdxTy);
>> } else // TODO: Remove with llvm 4.0
>> Op1 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
>> if (!Op1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> V = ConstantExpr::getExtractElement(Op0, Op1);
>> break;
>> }
>> @@ -1611,7 +1639,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> : { // CE_INSERTELT: [opval, opval, opty, opval]
>> VectorType *OpTy = dyn_cast<VectorType>(CurTy);
>> if (Record.size() < 3 || !OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
>> Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
>> OpTy->getElementType());
>> @@ -1619,19 +1647,19 @@ std::error_code BitcodeReader::ParseConstants() {
>> if (Record.size() == 4) {
>> Type *IdxTy = getTypeByID(Record[2]);
>> if (!IdxTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Op2 = ValueList.getConstantFwdRef(Record[3], IdxTy);
>> } else // TODO: Remove with llvm 4.0
>> Op2 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
>> if (!Op2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> V = ConstantExpr::getInsertElement(Op0, Op1, Op2);
>> break;
>> }
>> case bitc::CST_CODE_CE_SHUFFLEVEC: { // CE_SHUFFLEVEC: [opval, opval, opval]
>> VectorType *OpTy = dyn_cast<VectorType>(CurTy);
>> if (Record.size() < 3 || !OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
>> Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
>> Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
>> @@ -1645,7 +1673,7 @@ std::error_code BitcodeReader::ParseConstants() {
>> VectorType *OpTy =
>> dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
>> if (Record.size() < 4 || !RTy || !OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
>> Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
>> Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
>> @@ -1656,10 +1684,10 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred]
>> if (Record.size() < 4)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *OpTy = getTypeByID(Record[0]);
>> if (!OpTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
>> Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
>>
>> @@ -1673,16 +1701,16 @@ std::error_code BitcodeReader::ParseConstants() {
>> // FIXME: Remove with the 4.0 release.
>> case bitc::CST_CODE_INLINEASM_OLD: {
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> std::string AsmStr, ConstrStr;
>> bool HasSideEffects = Record[0] & 1;
>> bool IsAlignStack = Record[0] >> 1;
>> unsigned AsmStrSize = Record[1];
>> if (2+AsmStrSize >= Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned ConstStrSize = Record[2+AsmStrSize];
>> if (3+AsmStrSize+ConstStrSize > Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> for (unsigned i = 0; i != AsmStrSize; ++i)
>> AsmStr += (char)Record[2+i];
>> @@ -1697,17 +1725,17 @@ std::error_code BitcodeReader::ParseConstants() {
>> // inteldialect).
>> case bitc::CST_CODE_INLINEASM: {
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> std::string AsmStr, ConstrStr;
>> bool HasSideEffects = Record[0] & 1;
>> bool IsAlignStack = (Record[0] >> 1) & 1;
>> unsigned AsmDialect = Record[0] >> 2;
>> unsigned AsmStrSize = Record[1];
>> if (2+AsmStrSize >= Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned ConstStrSize = Record[2+AsmStrSize];
>> if (3+AsmStrSize+ConstStrSize > Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> for (unsigned i = 0; i != AsmStrSize; ++i)
>> AsmStr += (char)Record[2+i];
>> @@ -1721,14 +1749,14 @@ std::error_code BitcodeReader::ParseConstants() {
>> }
>> case bitc::CST_CODE_BLOCKADDRESS:{
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *FnTy = getTypeByID(Record[0]);
>> if (!FnTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Function *Fn =
>> dyn_cast_or_null<Function>(ValueList.getConstantFwdRef(Record[1],FnTy));
>> if (!Fn)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Don't let Fn get dematerialized.
>> BlockAddressesTaken.insert(Fn);
>> @@ -1739,12 +1767,12 @@ std::error_code BitcodeReader::ParseConstants() {
>> unsigned BBID = Record[2];
>> if (!BBID)
>> // Invalid reference to entry block.
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (!Fn->empty()) {
>> Function::iterator BBI = Fn->begin(), BBE = Fn->end();
>> for (size_t I = 0, E = BBID; I != E; ++I) {
>> if (BBI == BBE)
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> ++BBI;
>> }
>> BB = BBI;
>> @@ -1772,7 +1800,7 @@ std::error_code BitcodeReader::ParseConstants() {
>>
>> std::error_code BitcodeReader::ParseUseLists() {
>> if (Stream.EnterSubBlock(bitc::USELIST_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Read all the records.
>> SmallVector<uint64_t, 64> Record;
>> @@ -1782,7 +1810,7 @@ std::error_code BitcodeReader::ParseUseLists() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>> case BitstreamEntry::Record:
>> @@ -1803,7 +1831,7 @@ std::error_code BitcodeReader::ParseUseLists() {
>> unsigned RecordLength = Record.size();
>> if (RecordLength < 3)
>> // Records should have at least an ID and two indexes.
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned ID = Record.back();
>> Record.pop_back();
>>
>> @@ -1840,7 +1868,7 @@ std::error_code BitcodeReader::ParseUseLists() {
>> std::error_code BitcodeReader::RememberAndSkipFunctionBody() {
>> // Get the function we are talking about.
>> if (FunctionsWithBodies.empty())
>> - return Error(BitcodeError::InsufficientFunctionProtos);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Function *Fn = FunctionsWithBodies.back();
>> FunctionsWithBodies.pop_back();
>> @@ -1851,7 +1879,7 @@ std::error_code BitcodeReader::RememberAndSkipFunctionBody() {
>>
>> // Skip over the function block for now.
>> if (Stream.SkipBlock())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> return std::error_code();
>> }
>>
>> @@ -1859,7 +1887,7 @@ std::error_code BitcodeReader::GlobalCleanup() {
>> // Patch the initializers for globals and aliases up.
>> ResolveGlobalAndAliasInits();
>> if (!GlobalInits.empty() || !AliasInits.empty())
>> - return Error(BitcodeError::MalformedGlobalInitializerSet);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Look for intrinsic functions which need to be upgraded at some point
>> for (Module::iterator FI = TheModule->begin(), FE = TheModule->end();
>> @@ -1888,7 +1916,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> if (Resume)
>> Stream.JumpToBit(NextUnreadBit);
>> else if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>> std::vector<std::string> SectionTable;
>> @@ -1900,7 +1928,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>>
>> switch (Entry.Kind) {
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return GlobalCleanup();
>>
>> @@ -1908,11 +1936,11 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> switch (Entry.ID) {
>> default: // Skip unknown content.
>> if (Stream.SkipBlock())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> case bitc::BLOCKINFO_BLOCK_ID:
>> if (Stream.ReadBlockInfoBlock())
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> case bitc::PARAMATTR_BLOCK_ID:
>> if (std::error_code EC = ParseAttributeBlock())
>> @@ -1982,12 +2010,12 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> default: break; // Default behavior, ignore unknown content.
>> case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
>> if (Record.size() < 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> // Only version #0 and #1 are supported so far.
>> unsigned module_version = Record[0];
>> switch (module_version) {
>> default:
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case 0:
>> UseRelativeIDs = false;
>> break;
>> @@ -2000,21 +2028,21 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> TheModule->setTargetTriple(S);
>> break;
>> }
>> case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> TheModule->setDataLayout(S);
>> break;
>> }
>> case bitc::MODULE_CODE_ASM: { // ASM: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> TheModule->setModuleInlineAsm(S);
>> break;
>> }
>> @@ -2022,27 +2050,27 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> // FIXME: Remove in 4.0.
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> // Ignore value.
>> break;
>> }
>> case bitc::MODULE_CODE_SECTIONNAME: { // SECTIONNAME: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SectionTable.push_back(S);
>> break;
>> }
>> case bitc::MODULE_CODE_GCNAME: { // SECTIONNAME: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> GCTable.push_back(S);
>> break;
>> }
>> case bitc::MODULE_CODE_COMDAT: { // COMDAT: [selection_kind, name]
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Comdat::SelectionKind SK = getDecodedComdatSelectionKind(Record[0]);
>> unsigned ComdatNameSize = Record[1];
>> std::string ComdatName;
>> @@ -2059,12 +2087,12 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> // unnamed_addr, dllstorageclass]
>> case bitc::MODULE_CODE_GLOBALVAR: {
>> if (Record.size() < 6)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *Ty = getTypeByID(Record[0]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (!Ty->isPointerTy())
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
>> Ty = cast<PointerType>(Ty)->getElementType();
>>
>> @@ -2074,7 +2102,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> std::string Section;
>> if (Record[5]) {
>> if (Record[5]-1 >= SectionTable.size())
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Section = SectionTable[Record[5]-1];
>> }
>> GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
>> @@ -2127,16 +2155,16 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> // prologuedata, dllstorageclass, comdat, prefixdata]
>> case bitc::MODULE_CODE_FUNCTION: {
>> if (Record.size() < 8)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *Ty = getTypeByID(Record[0]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode, "Invalid record");
>> if (!Ty->isPointerTy())
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> FunctionType *FTy =
>> dyn_cast<FunctionType>(cast<PointerType>(Ty)->getElementType());
>> if (!FTy)
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage,
>> "", TheModule);
>> @@ -2149,7 +2177,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> Func->setAlignment((1 << Record[5]) >> 1);
>> if (Record[6]) {
>> if (Record[6]-1 >= SectionTable.size())
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Func->setSection(SectionTable[Record[6]-1]);
>> }
>> // Local linkage must have default visibility.
>> @@ -2158,7 +2186,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> Func->setVisibility(GetDecodedVisibility(Record[7]));
>> if (Record.size() > 8 && Record[8]) {
>> if (Record[8]-1 > GCTable.size())
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Func->setGC(GCTable[Record[8]-1].c_str());
>> }
>> bool UnnamedAddr = false;
>> @@ -2198,13 +2226,13 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
>> case bitc::MODULE_CODE_ALIAS: {
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *Ty = getTypeByID(Record[0]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> auto *PTy = dyn_cast<PointerType>(Ty);
>> if (!PTy)
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> auto *NewGA =
>> GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
>> @@ -2230,7 +2258,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume) {
>> case bitc::MODULE_CODE_PURGEVALS:
>> // Trim down the value list to the specified size.
>> if (Record.size() < 1 || Record[0] > ValueList.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> ValueList.shrinkTo(Record[0]);
>> break;
>> }
>> @@ -2251,7 +2279,7 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) {
>> Stream.Read(4) != 0xC ||
>> Stream.Read(4) != 0xE ||
>> Stream.Read(4) != 0xD)
>> - return Error(BitcodeError::InvalidBitcodeSignature);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // We expect a number of well-defined blocks, though we don't necessarily
>> // need to understand them all.
>> @@ -2264,7 +2292,7 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) {
>>
>> switch (Entry.Kind) {
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode, "Malformed block");
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>>
>> @@ -2272,12 +2300,12 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) {
>> switch (Entry.ID) {
>> case bitc::BLOCKINFO_BLOCK_ID:
>> if (Stream.ReadBlockInfoBlock())
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> case bitc::MODULE_BLOCK_ID:
>> // Reject multiple MODULE_BLOCK's in a single bitstream.
>> if (TheModule)
>> - return Error(BitcodeError::InvalidMultipleBlocks);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> TheModule = M;
>> if (std::error_code EC = ParseModule(false))
>> return EC;
>> @@ -2286,7 +2314,7 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) {
>> break;
>> default:
>> if (Stream.SkipBlock())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> }
>> continue;
>> @@ -2301,14 +2329,14 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) {
>> Stream.AtEndOfStream())
>> return std::error_code();
>>
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> }
>> }
>>
>> ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
>> if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>>
>> @@ -2320,7 +2348,7 @@ ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return Triple;
>> case BitstreamEntry::Record:
>> @@ -2334,7 +2362,7 @@ ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
>> case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N]
>> std::string S;
>> if (ConvertToString(Record, 0, S))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Triple = S;
>> break;
>> }
>> @@ -2355,7 +2383,7 @@ ErrorOr<std::string> BitcodeReader::parseTriple() {
>> Stream.Read(4) != 0xC ||
>> Stream.Read(4) != 0xE ||
>> Stream.Read(4) != 0xD)
>> - return Error(BitcodeError::InvalidBitcodeSignature);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // We expect a number of well-defined blocks, though we don't necessarily
>> // need to understand them all.
>> @@ -2364,7 +2392,7 @@ ErrorOr<std::string> BitcodeReader::parseTriple() {
>>
>> switch (Entry.Kind) {
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>>
>> @@ -2374,7 +2402,7 @@ ErrorOr<std::string> BitcodeReader::parseTriple() {
>>
>> // Ignore other sub-blocks.
>> if (Stream.SkipBlock())
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> continue;
>>
>> case BitstreamEntry::Record:
>> @@ -2387,7 +2415,7 @@ ErrorOr<std::string> BitcodeReader::parseTriple() {
>> /// ParseMetadataAttachment - Parse metadata attachments.
>> std::error_code BitcodeReader::ParseMetadataAttachment() {
>> if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<uint64_t, 64> Record;
>> while (1) {
>> @@ -2396,7 +2424,7 @@ std::error_code BitcodeReader::ParseMetadataAttachment() {
>> switch (Entry.Kind) {
>> case BitstreamEntry::SubBlock: // Handled for us already.
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> return std::error_code();
>> case BitstreamEntry::Record:
>> @@ -2412,14 +2440,14 @@ std::error_code BitcodeReader::ParseMetadataAttachment() {
>> case bitc::METADATA_ATTACHMENT: {
>> unsigned RecordLength = Record.size();
>> if (Record.empty() || (RecordLength - 1) % 2 == 1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Instruction *Inst = InstructionList[Record[0]];
>> for (unsigned i = 1; i != RecordLength; i = i+2) {
>> unsigned Kind = Record[i];
>> DenseMap<unsigned, unsigned>::iterator I =
>> MDKindMap.find(Kind);
>> if (I == MDKindMap.end())
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Metadata *Node = MDValueList.getValueFwdRef(Record[i + 1]);
>> if (isa<LocalAsMetadata>(Node))
>> // Drop the attachment. This used to be legal, but there's no
>> @@ -2438,7 +2466,7 @@ std::error_code BitcodeReader::ParseMetadataAttachment() {
>> /// ParseFunctionBody - Lazily parse the specified function body block.
>> std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> InstructionList.clear();
>> unsigned ModuleValueListSize = ValueList.size();
>> @@ -2469,7 +2497,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>>
>> switch (Entry.Kind) {
>> case BitstreamEntry::Error:
>> - return Error(BitcodeError::MalformedBlock);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case BitstreamEntry::EndBlock:
>> goto OutOfRecordLoop;
>>
>> @@ -2477,7 +2505,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> switch (Entry.ID) {
>> default: // Skip unknown content.
>> if (Stream.SkipBlock())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> break;
>> case bitc::CONSTANTS_BLOCK_ID:
>> if (std::error_code EC = ParseConstants())
>> @@ -2514,10 +2542,10 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned BitCode = Stream.readRecord(Entry.ID, Record);
>> switch (BitCode) {
>> default: // Default behavior: reject
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> case bitc::FUNC_CODE_DECLAREBLOCKS: { // DECLAREBLOCKS: [nblocks]
>> if (Record.size() < 1 || Record[0] == 0)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> // Create all the basic blocks for the function.
>> FunctionBBs.resize(Record[0]);
>>
>> @@ -2530,7 +2558,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> auto &BBRefs = BBFRI->second;
>> // Check for invalid basic block references.
>> if (BBRefs.size() > FunctionBBs.size())
>> - return Error(BitcodeError::InvalidID);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> assert(!BBRefs.empty() && "Unexpected empty array");
>> assert(!BBRefs.front() && "Invalid reference to entry block");
>> for (unsigned I = 0, E = FunctionBBs.size(), RE = BBRefs.size(); I != E;
>> @@ -2556,7 +2584,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> I = getLastInstruction();
>>
>> if (!I)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I->setDebugLoc(LastLoc);
>> I = nullptr;
>> continue;
>> @@ -2564,7 +2592,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> case bitc::FUNC_CODE_DEBUG_LOC_OLD: { // DEBUG_LOC_OLD: [line,col,scope,ia]
>> I = getLastInstruction();
>> if (!I || Record.size() < 4)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> unsigned Line = Record[0], Col = Record[1];
>> unsigned ScopeID = Record[2], IAID = Record[3];
>> @@ -2584,11 +2612,11 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
>> popValue(Record, OpNum, NextValueNo, LHS->getType(), RHS) ||
>> OpNum+1 > Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> int Opc = GetDecodedBinaryOpcode(Record[OpNum++], LHS->getType());
>> if (Opc == -1)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS);
>> InstructionList.push_back(I);
>> if (OpNum < Record.size()) {
>> @@ -2630,12 +2658,12 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
>> OpNum+2 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> Type *ResTy = getTypeByID(Record[OpNum]);
>> int Opc = GetDecodedCastOpcode(Record[OpNum+1]);
>> if (Opc == -1 || !ResTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Instruction *Temp = nullptr;
>> if ((I = UpgradeBitCastInst(Opc, Op, ResTy, Temp))) {
>> if (Temp) {
>> @@ -2653,13 +2681,13 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 0;
>> Value *BasePtr;
>> if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<Value*, 16> GEPIdx;
>> while (OpNum != Record.size()) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> GEPIdx.push_back(Op);
>> }
>>
>> @@ -2675,14 +2703,14 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 0;
>> Value *Agg;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<unsigned, 4> EXTRACTVALIdx;
>> for (unsigned RecSize = Record.size();
>> OpNum != RecSize; ++OpNum) {
>> uint64_t Index = Record[OpNum];
>> if ((unsigned)Index != Index)
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> EXTRACTVALIdx.push_back((unsigned)Index);
>> }
>>
>> @@ -2696,17 +2724,17 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 0;
>> Value *Agg;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Value *Val;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Val))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<unsigned, 4> INSERTVALIdx;
>> for (unsigned RecSize = Record.size();
>> OpNum != RecSize; ++OpNum) {
>> uint64_t Index = Record[OpNum];
>> if ((unsigned)Index != Index)
>> - return Error(BitcodeError::InvalidValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> INSERTVALIdx.push_back((unsigned)Index);
>> }
>>
>> @@ -2723,7 +2751,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
>> popValue(Record, OpNum, NextValueNo, TrueVal->getType(), FalseVal) ||
>> popValue(Record, OpNum, NextValueNo, Type::getInt1Ty(Context), Cond))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> I = SelectInst::Create(Cond, TrueVal, FalseVal);
>> InstructionList.push_back(I);
>> @@ -2738,18 +2766,18 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
>> popValue(Record, OpNum, NextValueNo, TrueVal->getType(), FalseVal) ||
>> getValueTypePair(Record, OpNum, NextValueNo, Cond))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // select condition can be either i1 or [N x i1]
>> if (VectorType* vector_type =
>> dyn_cast<VectorType>(Cond->getType())) {
>> // expect <n x i1>
>> if (vector_type->getElementType() != Type::getInt1Ty(Context))
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> } else {
>> // expect i1
>> if (Cond->getType() != Type::getInt1Ty(Context))
>> - return Error(BitcodeError::InvalidTypeForValue);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>>
>> I = SelectInst::Create(Cond, TrueVal, FalseVal);
>> @@ -2762,7 +2790,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Vec, *Idx;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
>> getValueTypePair(Record, OpNum, NextValueNo, Idx))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = ExtractElementInst::Create(Vec, Idx);
>> InstructionList.push_back(I);
>> break;
>> @@ -2775,7 +2803,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> popValue(Record, OpNum, NextValueNo,
>> cast<VectorType>(Vec->getType())->getElementType(), Elt) ||
>> getValueTypePair(Record, OpNum, NextValueNo, Idx))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = InsertElementInst::Create(Vec, Elt, Idx);
>> InstructionList.push_back(I);
>> break;
>> @@ -2786,10 +2814,10 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Vec1, *Vec2, *Mask;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Vec1) ||
>> popValue(Record, OpNum, NextValueNo, Vec1->getType(), Vec2))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (getValueTypePair(Record, OpNum, NextValueNo, Mask))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = new ShuffleVectorInst(Vec1, Vec2, Mask);
>> InstructionList.push_back(I);
>> break;
>> @@ -2807,7 +2835,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
>> popValue(Record, OpNum, NextValueNo, LHS->getType(), RHS) ||
>> OpNum+1 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (LHS->getType()->isFPOrFPVectorTy())
>> I = new FCmpInst((FCmpInst::Predicate)Record[OpNum], LHS, RHS);
>> @@ -2829,9 +2857,9 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 0;
>> Value *Op = nullptr;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (OpNum != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> I = ReturnInst::Create(Context, Op);
>> InstructionList.push_back(I);
>> @@ -2839,10 +2867,10 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> }
>> case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
>> if (Record.size() != 1 && Record.size() != 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> BasicBlock *TrueDest = getBasicBlock(Record[0]);
>> if (!TrueDest)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> if (Record.size() == 1) {
>> I = BranchInst::Create(TrueDest);
>> @@ -2853,7 +2881,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Cond = getValue(Record, 2, NextValueNo,
>> Type::getInt1Ty(Context));
>> if (!FalseDest || !Cond)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = BranchInst::Create(TrueDest, FalseDest, Cond);
>> InstructionList.push_back(I);
>> }
>> @@ -2873,7 +2901,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Cond = getValue(Record, 2, NextValueNo, OpTy);
>> BasicBlock *Default = getBasicBlock(Record[3]);
>> if (!OpTy || !Cond || !Default)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> unsigned NumCases = Record[4];
>>
>> @@ -2925,12 +2953,12 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> // Old SwitchInst format without case ranges.
>>
>> if (Record.size() < 3 || (Record.size() & 1) == 0)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *OpTy = getTypeByID(Record[0]);
>> Value *Cond = getValue(Record, 1, NextValueNo, OpTy);
>> BasicBlock *Default = getBasicBlock(Record[2]);
>> if (!OpTy || !Cond || !Default)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned NumCases = (Record.size()-3)/2;
>> SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
>> InstructionList.push_back(SI);
>> @@ -2940,7 +2968,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
>> if (!CaseVal || !DestBB) {
>> delete SI;
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> SI->addCase(CaseVal, DestBB);
>> }
>> @@ -2949,11 +2977,11 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> }
>> case bitc::FUNC_CODE_INST_INDIRECTBR: { // INDIRECTBR: [opty, op0, op1, ...]
>> if (Record.size() < 2)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *OpTy = getTypeByID(Record[0]);
>> Value *Address = getValue(Record, 1, NextValueNo, OpTy);
>> if (!OpTy || !Address)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> unsigned NumDests = Record.size()-2;
>> IndirectBrInst *IBI = IndirectBrInst::Create(Address, NumDests);
>> InstructionList.push_back(IBI);
>> @@ -2962,7 +2990,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> IBI->addDestination(DestBB);
>> } else {
>> delete IBI;
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> }
>> I = IBI;
>> @@ -2972,7 +3000,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> case bitc::FUNC_CODE_INST_INVOKE: {
>> // INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
>> if (Record.size() < 4)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AttributeSet PAL = getAttributes(Record[0]);
>> unsigned CCInfo = Record[1];
>> BasicBlock *NormalBB = getBasicBlock(Record[2]);
>> @@ -2981,7 +3009,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 4;
>> Value *Callee;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> PointerType *CalleeTy = dyn_cast<PointerType>(Callee->getType());
>> FunctionType *FTy = !CalleeTy ? nullptr :
>> @@ -2990,25 +3018,25 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> // Check that the right number of fixed parameters are here.
>> if (!FTy || !NormalBB || !UnwindBB ||
>> Record.size() < OpNum+FTy->getNumParams())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<Value*, 16> Ops;
>> for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
>> Ops.push_back(getValue(Record, OpNum, NextValueNo,
>> FTy->getParamType(i)));
>> if (!Ops.back())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>>
>> if (!FTy->isVarArg()) {
>> if (Record.size() != OpNum)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> } else {
>> // Read type/value pairs for varargs params.
>> while (OpNum != Record.size()) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Ops.push_back(Op);
>> }
>> }
>> @@ -3024,7 +3052,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned Idx = 0;
>> Value *Val = nullptr;
>> if (getValueTypePair(Record, Idx, NextValueNo, Val))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = ResumeInst::Create(Val);
>> InstructionList.push_back(I);
>> break;
>> @@ -3035,10 +3063,10 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> break;
>> case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...]
>> if (Record.size() < 1 || ((Record.size()-1)&1))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *Ty = getTypeByID(Record[0]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> PHINode *PN = PHINode::Create(Ty, (Record.size()-1)/2);
>> InstructionList.push_back(PN);
>> @@ -3054,7 +3082,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> V = getValue(Record, 1+i, NextValueNo, Ty);
>> BasicBlock *BB = getBasicBlock(Record[2+i]);
>> if (!V || !BB)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> PN->addIncoming(V, BB);
>> }
>> I = PN;
>> @@ -3065,13 +3093,13 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> // LANDINGPAD: [ty, val, val, num, (id0,val0 ...)?]
>> unsigned Idx = 0;
>> if (Record.size() < 4)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *Ty = getTypeByID(Record[Idx++]);
>> if (!Ty)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Value *PersFn = nullptr;
>> if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> bool IsCleanup = !!Record[Idx++];
>> unsigned NumClauses = Record[Idx++];
>> @@ -3084,7 +3112,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>>
>> if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
>> delete LP;
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>>
>> assert((CT != LandingPadInst::Catch ||
>> @@ -3103,7 +3131,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>>
>> case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, opty, op, align]
>> if (Record.size() != 4)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> PointerType *Ty =
>> dyn_cast_or_null<PointerType>(getTypeByID(Record[0]));
>> Type *OpTy = getTypeByID(Record[1]);
>> @@ -3112,7 +3140,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> bool InAlloca = AlignRecord & (1 << 5);
>> unsigned Align = AlignRecord & ((1 << 5) - 1);
>> if (!Ty || !Size)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AllocaInst *AI = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
>> AI->setUsedWithInAlloca(InAlloca);
>> I = AI;
>> @@ -3124,7 +3152,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
>> OpNum+2 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1);
>> InstructionList.push_back(I);
>> @@ -3136,14 +3164,14 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
>> OpNum+4 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> AtomicOrdering Ordering = GetDecodedOrdering(Record[OpNum+2]);
>> if (Ordering == NotAtomic || Ordering == Release ||
>> Ordering == AcquireRelease)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> if (Ordering != NotAtomic && Record[OpNum] == 0)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SynchronizationScope SynchScope = GetDecodedSynchScope(Record[OpNum+3]);
>>
>> I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1,
>> @@ -3158,7 +3186,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> popValue(Record, OpNum, NextValueNo,
>> cast<PointerType>(Ptr->getType())->getElementType(), Val) ||
>> OpNum+2 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1);
>> InstructionList.push_back(I);
>> @@ -3172,15 +3200,15 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> popValue(Record, OpNum, NextValueNo,
>> cast<PointerType>(Ptr->getType())->getElementType(), Val) ||
>> OpNum+4 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> AtomicOrdering Ordering = GetDecodedOrdering(Record[OpNum+2]);
>> if (Ordering == NotAtomic || Ordering == Acquire ||
>> Ordering == AcquireRelease)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SynchronizationScope SynchScope = GetDecodedSynchScope(Record[OpNum+3]);
>> if (Ordering != NotAtomic && Record[OpNum] == 0)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1,
>> Ordering, SynchScope);
>> @@ -3198,10 +3226,10 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> popValue(Record, OpNum, NextValueNo,
>> cast<PointerType>(Ptr->getType())->getElementType(), New) ||
>> (Record.size() < OpNum + 3 || Record.size() > OpNum + 5))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AtomicOrdering SuccessOrdering = GetDecodedOrdering(Record[OpNum+1]);
>> if (SuccessOrdering == NotAtomic || SuccessOrdering == Unordered)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SynchronizationScope SynchScope = GetDecodedSynchScope(Record[OpNum+2]);
>>
>> AtomicOrdering FailureOrdering;
>> @@ -3236,14 +3264,14 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> popValue(Record, OpNum, NextValueNo,
>> cast<PointerType>(Ptr->getType())->getElementType(), Val) ||
>> OpNum+4 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AtomicRMWInst::BinOp Operation = GetDecodedRMWOperation(Record[OpNum]);
>> if (Operation < AtomicRMWInst::FIRST_BINOP ||
>> Operation > AtomicRMWInst::LAST_BINOP)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AtomicOrdering Ordering = GetDecodedOrdering(Record[OpNum+2]);
>> if (Ordering == NotAtomic || Ordering == Unordered)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SynchronizationScope SynchScope = GetDecodedSynchScope(Record[OpNum+3]);
>> I = new AtomicRMWInst(Operation, Ptr, Val, Ordering, SynchScope);
>> cast<AtomicRMWInst>(I)->setVolatile(Record[OpNum+1]);
>> @@ -3252,11 +3280,11 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> }
>> case bitc::FUNC_CODE_INST_FENCE: { // FENCE:[ordering, synchscope]
>> if (2 != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> AtomicOrdering Ordering = GetDecodedOrdering(Record[0]);
>> if (Ordering == NotAtomic || Ordering == Unordered ||
>> Ordering == Monotonic)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> SynchronizationScope SynchScope = GetDecodedSynchScope(Record[1]);
>> I = new FenceInst(Context, Ordering, SynchScope);
>> InstructionList.push_back(I);
>> @@ -3265,7 +3293,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> case bitc::FUNC_CODE_INST_CALL: {
>> // CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> AttributeSet PAL = getAttributes(Record[0]);
>> unsigned CCInfo = Record[1];
>> @@ -3273,13 +3301,13 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> unsigned OpNum = 2;
>> Value *Callee;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> PointerType *OpTy = dyn_cast<PointerType>(Callee->getType());
>> FunctionType *FTy = nullptr;
>> if (OpTy) FTy = dyn_cast<FunctionType>(OpTy->getElementType());
>> if (!FTy || Record.size() < FTy->getNumParams()+OpNum)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> SmallVector<Value*, 16> Args;
>> // Read the fixed params.
>> @@ -3290,18 +3318,18 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> Args.push_back(getValue(Record, OpNum, NextValueNo,
>> FTy->getParamType(i)));
>> if (!Args.back())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>>
>> // Read type/value pairs for varargs params.
>> if (!FTy->isVarArg()) {
>> if (OpNum != Record.size())
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> } else {
>> while (OpNum != Record.size()) {
>> Value *Op;
>> if (getValueTypePair(Record, OpNum, NextValueNo, Op))
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Args.push_back(Op);
>> }
>> }
>> @@ -3321,12 +3349,12 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> }
>> case bitc::FUNC_CODE_INST_VAARG: { // VAARG: [valistty, valist, instty]
>> if (Record.size() < 3)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> Type *OpTy = getTypeByID(Record[0]);
>> Value *Op = getValue(Record, 1, NextValueNo, OpTy);
>> Type *ResTy = getTypeByID(Record[2]);
>> if (!OpTy || !Op || !ResTy)
>> - return Error(BitcodeError::InvalidRecord);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> I = new VAArgInst(Op, ResTy);
>> InstructionList.push_back(I);
>> break;
>> @@ -3337,7 +3365,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
>> // this file.
>> if (!CurBB) {
>> delete I;
>> - return Error(BitcodeError::InvalidInstructionWithNoBB);
>> + return Error(BitcodeError::CorrupteddBitcode);
>> }
>> CurBB->getInstList().push_back(I);
>>
>> @@ -3364,7 +3392,8 @@ OutOfRecordLoop:
>> delete A;
>> }
>> }
>> - return Error(BitcodeError::NeverResolvedValueFoundInFunction);
>> + return Error(BitcodeError::CorrupteddBitcode,
>> + "Never resolved value found in function");
>> }
>> }
>>
>> @@ -3384,7 +3413,7 @@ std::error_code BitcodeReader::FindFunctionInStream(
>> DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator) {
>> while (DeferredFunctionInfoIterator->second == 0) {
>> if (Stream.AtEndOfStream())
>> - return Error(BitcodeError::CouldNotFindFunctionInStream);
>> + return Error(BitcodeError::CorrupteddBitcode);
>
> Another one where it seems useful to have a good error message.
>
>> // ParseModule will parse the next body in the stream and set its
>> // position in the DeferredFunctionInfo map.
>> if (std::error_code EC = ParseModule(true))
>> @@ -3486,7 +3515,7 @@ std::error_code BitcodeReader::MaterializeModule(Module *M) {
>> // Check that all block address forward references got resolved (as we
>> // promised above).
>> if (!BasicBlockFwdRefs.empty())
>> - return Error(BitcodeError::NeverResolvedFunctionFromBlockAddress);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> // Upgrade any intrinsic calls that slipped through (should not happen!) and
>> // delete the old functions to clean up. We can't do this unless the entire
>> @@ -3535,7 +3564,7 @@ std::error_code BitcodeReader::InitStreamFromBuffer() {
>> // The magic number is 0x0B17C0DE stored in little endian.
>> if (isBitcodeWrapper(BufPtr, BufEnd))
>> if (SkipBitcodeWrapperHeader(BufPtr, BufEnd, true))
>> - return Error(BitcodeError::InvalidBitcodeWrapperHeader);
>> + return Error(BitcodeError::CorrupteddBitcode);
>>
>> StreamFile.reset(new BitstreamReader(BufPtr, BufEnd));
>> Stream.init(&*StreamFile);
>> @@ -3576,44 +3605,10 @@ class BitcodeErrorCategoryType : public std::error_category {
>> std::string message(int IE) const override {
>> BitcodeError E = static_cast<BitcodeError>(IE);
>> switch (E) {
>> - case BitcodeError::ConflictingMETADATA_KINDRecords:
>> - return "Conflicting METADATA_KIND records";
>> - case BitcodeError::CouldNotFindFunctionInStream:
>> - return "Could not find function in stream";
>> - case BitcodeError::ExpectedConstant:
>> - return "Expected a constant";
>> - case BitcodeError::InsufficientFunctionProtos:
>> - return "Insufficient function protos";
>> case BitcodeError::InvalidBitcodeSignature:
>> return "Invalid bitcode signature";
>> - case BitcodeError::InvalidBitcodeWrapperHeader:
>> - return "Invalid bitcode wrapper header";
>> - case BitcodeError::InvalidConstantReference:
>> - return "Invalid ronstant reference";
>> - case BitcodeError::InvalidID:
>> - return "Invalid ID";
>> - case BitcodeError::InvalidInstructionWithNoBB:
>> - return "Invalid instruction with no BB";
>> - case BitcodeError::InvalidRecord:
>> - return "Invalid record";
>> - case BitcodeError::InvalidTypeForValue:
>> - return "Invalid type for value";
>> - case BitcodeError::InvalidTYPETable:
>> - return "Invalid TYPE table";
>> - case BitcodeError::InvalidType:
>> - return "Invalid type";
>> - case BitcodeError::MalformedBlock:
>> - return "Malformed block";
>> - case BitcodeError::MalformedGlobalInitializerSet:
>> - return "Malformed global initializer set";
>> - case BitcodeError::InvalidMultipleBlocks:
>> - return "Invalid multiple blocks";
>> - case BitcodeError::NeverResolvedValueFoundInFunction:
>> - return "Never resolved value found in function";
>> - case BitcodeError::NeverResolvedFunctionFromBlockAddress:
>> - return "Never resolved function from blockaddress";
>> - case BitcodeError::InvalidValue:
>> - return "Invalid value";
>> + case BitcodeError::CorrupteddBitcode:
>> + return "Corrupted bitcode";
>> }
>> llvm_unreachable("Unknown error type!");
>> }
>> diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
>> index 639ddb9..39f23ff 100644
>> --- a/lib/Bitcode/Reader/BitcodeReader.h
>> +++ b/lib/Bitcode/Reader/BitcodeReader.h
>> @@ -210,7 +210,8 @@ class BitcodeReader : public GVMaterializer {
>> SmallPtrSet<const Function *, 4> BlockAddressesTaken;
>>
>> public:
>> - std::error_code Error(BitcodeError E) { return make_error_code(E); }
>> + std::error_code Error(BitcodeError E, const Twine &Message);
>> + std::error_code Error(BitcodeError E);
>>
>> explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
>> : Context(C), TheModule(nullptr), Buffer(buffer), LazyStreamer(nullptr),
>> diff --git a/test/Bitcode/invalid.ll b/test/Bitcode/invalid.ll
>> index 1d4a82b..8b532d8 100644
>> --- a/test/Bitcode/invalid.ll
>> +++ b/test/Bitcode/invalid.ll
>> @@ -1,6 +1,6 @@
>> ; RUN: not llvm-dis < %s.bc 2>&1 | FileCheck %s
>>
>> -; CHECK: llvm-dis{{(\.EXE|\.exe)?}}: Invalid value
>> +; CHECK: llvm-dis{{(\.EXE|\.exe)?}}: Unknown attribute kind (48)
>>
>> ; invalid.ll.bc has an invalid attribute number.
>> ; The test checks that LLVM reports the error and doesn't access freed memory
>> diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
>> index 6b58644..f610f46 100644
>> --- a/tools/gold/gold-plugin.cpp
>> +++ b/tools/gold/gold-plugin.cpp
>> @@ -19,6 +19,8 @@
>> #include "llvm/CodeGen/Analysis.h"
>> #include "llvm/CodeGen/CommandFlags.h"
>> #include "llvm/IR/Constants.h"
>> +#include "llvm/IR/DiagnosticInfo.h"
>> +#include "llvm/IR/DiagnosticPrinter.h"
>> #include "llvm/IR/LLVMContext.h"
>> #include "llvm/IR/Module.h"
>> #include "llvm/IR/Verifier.h"
>> @@ -269,6 +271,24 @@ static bool shouldSkip(uint32_t Symflags) {
>> return false;
>> }
>>
>> +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
>> + assert(DI.getSeverity() == DS_Error && "Only expecting errors");
>> + const auto &BDI = cast<BitcodeDiagnosticInfo>(DI);
>> + std::error_code EC = BDI.getError();
>> + if (EC == BitcodeError::InvalidBitcodeSignature)
>> + return;
>> +
>> + std::string ErrStorage;
>> + {
>> + raw_string_ostream OS(ErrStorage);
>> + DiagnosticPrinterRawOStream DP(OS);
>> + DI.print(DP);
>> + }
>> + message(LDPL_ERROR, "LLVM gold plugin has failed to create LTO module: %s",
>> + ErrStorage.c_str());
>> + exit(1);
>> +}
>> +
>> /// Called by gold to see whether this file is one that our plugin can handle.
>> /// We'll try to open it and register all the symbols with add_symbol if
>> /// possible.
>> @@ -302,11 +322,11 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
>> BufferRef = Buffer->getMemBufferRef();
>> }
>>
>> + Context.setDiagnosticHandler(diagnosticHandler);
>> ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
>> object::IRObjectFile::create(BufferRef, Context);
>> std::error_code EC = ObjOrErr.getError();
>> - if (EC == BitcodeError::InvalidBitcodeSignature ||
>> - EC == object::object_error::invalid_file_type ||
>> + if (EC == object::object_error::invalid_file_type ||
>> EC == object::object_error::bitcode_section_not_found)
>> return LDPS_OK;
>>
>> diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
>> index 072f636..1349ecc 100644
>> --- a/tools/llvm-dis/llvm-dis.cpp
>> +++ b/tools/llvm-dis/llvm-dis.cpp
>> @@ -20,6 +20,8 @@
>> #include "llvm/Bitcode/ReaderWriter.h"
>> #include "llvm/IR/AssemblyAnnotationWriter.h"
>> #include "llvm/IR/DebugInfo.h"
>> +#include "llvm/IR/DiagnosticInfo.h"
>> +#include "llvm/IR/DiagnosticPrinter.h"
>> #include "llvm/IR/IntrinsicInst.h"
>> #include "llvm/IR/Module.h"
>> #include "llvm/IR/Type.h"
>> @@ -112,6 +114,17 @@ public:
>>
>> } // end anon namespace
>>
>> +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
>> + assert(DI.getSeverity() == DS_Error && "Only expecting errors");
>> +
>> + raw_ostream &OS = errs();
>> + OS << (char *)Context << ": ";
>> + DiagnosticPrinterRawOStream DP(OS);
>> + DI.print(DP);
>> + OS << '\n';
>> + exit(1);
>> +}
>> +
>> int main(int argc, char **argv) {
>> // Print a stack trace if we signal out.
>> sys::PrintStackTraceOnErrorSignal();
>> @@ -120,6 +133,7 @@ int main(int argc, char **argv) {
>> LLVMContext &Context = getGlobalContext();
>> llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
>>
>> + Context.setDiagnosticHandler(diagnosticHandler, argv[0]);
>>
>> cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
>>
>> @@ -136,25 +150,8 @@ int main(int argc, char **argv) {
>> DisplayFilename = InputFilename;
>> ErrorOr<std::unique_ptr<Module>> MOrErr =
>> getStreamedBitcodeModule(DisplayFilename, Streamer, Context);
>> - if (std::error_code EC = MOrErr.getError())
>> - ErrorMessage = EC.message();
>> - else
>> - M = std::move(*MOrErr);
>> - if(M.get()) {
>> - if (std::error_code EC = M->materializeAllPermanently()) {
>> - ErrorMessage = EC.message();
>> - M.reset();
>> - }
>> - }
>> - }
>> -
>> - if (!M.get()) {
>> - errs() << argv[0] << ": ";
>> - if (ErrorMessage.size())
>> - errs() << ErrorMessage << "\n";
>> - else
>> - errs() << "bitcode didn't read correctly.\n";
>> - return 1;
>> + M = std::move(*MOrErr);
>> + M->materializeAllPermanently();
>> }
>>
>> // Just use stdout. We won't actually print anything on it.
>>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list