From f1d46144183af84c3210c2dfd8b5325ee20955b5 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 16 Mar 2015 21:35:48 +0000 Subject: [PATCH] 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) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232420 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 10 ++++++++-- .../invalid-gep-mismatched-explicit-type.bc | Bin 0 -> 448 bytes test/Bitcode/invalid.test | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 143bb3dad9e..a26c444c6cc 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/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(BasePtr->getType()->getScalarType()) + ->getElementType()) + return Error( + "Explicit gep type does not match pointee type of pointer operand"); + SmallVector 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(I)->getSourceElementType()) - return Error("Invalid record"); + InstructionList.push_back(I); if (InBounds) cast(I)->setIsInBounds(true); diff --git a/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc b/test/Bitcode/Inputs/invalid-gep-mismatched-explicit-type.bc new file mode 100644 index 0000000000000000000000000000000000000000..0d828e8c3296ddbf4f82c6e282823d11b6f1bb83 GIT binary patch literal 448 zcmZ>AK5$Qwhk+rNfq{X$Nr8b0NDBiod!zD1#}h1`Yyw7>lNeigR9QJB(Lja$#z!BMdiZVA8We+9Fr5SWu?`gKa;B2{t*=A3(O$)R2nGYgm z3GCGw?B*HmML@Ely~Z327B2LR-m!v4ejw9?S&HUMKjtfXEf@(`@r|^0pHgH zd~X;E6&S!_&E_Byq73v`B9PAwq=i`=bp(Jk$mdst7#Osh1X2X}SQwareD(l=vm%LN M1~$PgKpq4D06#;18UO$Q literal 0 HcmV?d00001 diff --git a/test/Bitcode/invalid.test b/test/Bitcode/invalid.test index fb818884eed..7eb28aa6fba 100644 --- a/test/Bitcode/invalid.test +++ b/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 -- 2.34.1