diff options
author | David Blaikie <dblaikie@gmail.com> | 2015-03-16 21:35:48 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2015-03-16 21:35:48 +0000 |
commit | 675e8cb09eefaf94db6be27dd65fb6627daae0d3 (patch) | |
tree | b8c56212cea95a46138e7a22080322ab861390c2 /llvm | |
parent | 9b7374b8216a0860fc0606e2db910a76cc729b20 (diff) | |
download | bcm5719-llvm-675e8cb09eefaf94db6be27dd65fb6627daae0d3.tar.gz bcm5719-llvm-675e8cb09eefaf94db6be27dd65fb6627daae0d3.zip |
Test bitcode parsing error-handling for incorrect explicit type
(turns out I had regressed this when sinking handling of this type down
into GetElementPtrInst::Create - since that asserted before the error
handling was performed)
llvm-svn: 232420
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 10 | ||||
-rw-r--r-- | llvm/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc | bin | 0 -> 448 bytes | |||
-rw-r--r-- | llvm/test/Bitcode/invalid.test | 3 |
3 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 143bb3dad9e..a26c444c6cc 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3123,6 +3123,13 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr)) return Error("Invalid record"); + if (Ty && + Ty != + cast<SequentialType>(BasePtr->getType()->getScalarType()) + ->getElementType()) + return Error( + "Explicit gep type does not match pointee type of pointer operand"); + SmallVector<Value*, 16> GEPIdx; while (OpNum != Record.size()) { Value *Op; @@ -3132,8 +3139,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { } I = GetElementPtrInst::Create(Ty, BasePtr, GEPIdx); - if (Ty && Ty != cast<GetElementPtrInst>(I)->getSourceElementType()) - return Error("Invalid record"); + InstructionList.push_back(I); if (InBounds) cast<GetElementPtrInst>(I)->setIsInBounds(true); diff --git a/llvm/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc b/llvm/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc Binary files differnew file mode 100644 index 00000000000..0d828e8c329 --- /dev/null +++ b/llvm/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index fb818884eed..7eb28aa6fba 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -12,6 +12,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-bitwidth.bc 2>&1 | \ RUN: FileCheck --check-prefix=BAD-BITWIDTH %s RUN: not llvm-dis -disable-output %p/Inputs/invalid-align.bc 2>&1 | \ RUN: FileCheck --check-prefix=BAD-ALIGN %s +RUN: not llvm-dis -disable-output %p/Inputs/invalid-gep-mismatched-explicit-type.bc 2>&1 | \ +RUN: FileCheck --check-prefix=MISMATCHED-EXPLICIT-GEP %s INVALID-ENCODING: Invalid encoding BAD-ABBREV: Abbreviation starts with an Array or a Blob @@ -20,6 +22,7 @@ BAD-ABBREV-NUMBER: Invalid abbrev number BAD-TYPE-TABLE-FORWARD-REF: Invalid TYPE table: Only named structs can be forward referenced BAD-BITWIDTH: Bitwidth for integer type out of range BAD-ALIGN: Invalid alignment value +MISMATCHED-EXPLICIT-GEP: Explicit gep type does not match pointee type of pointer operand RUN: not llvm-dis -disable-output %p/Inputs/invalid-extractval-array-idx.bc 2>&1 | \ RUN: FileCheck --check-prefix=EXTRACT-ARRAY %s |