From: David Blaikie Date: Fri, 24 Apr 2015 18:06:06 +0000 (+0000) Subject: [opaque pointer type] bitcode: add explicit callee type to invoke instructions X-Git-Tag: llvmorg-3.7.0-rc1~6050 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ea1f7b7440b7050abb912ce360c7cabcd8c2881;p=platform%2Fupstream%2Fllvm.git [opaque pointer type] bitcode: add explicit callee type to invoke instructions llvm-svn: 235735 --- diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 57cd1d4..5f7a5ea 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3863,24 +3863,33 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { // INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...] if (Record.size() < 4) return Error("Invalid record"); - AttributeSet PAL = getAttributes(Record[0]); - unsigned CCInfo = Record[1]; - BasicBlock *NormalBB = getBasicBlock(Record[2]); - BasicBlock *UnwindBB = getBasicBlock(Record[3]); + unsigned OpNum = 0; + AttributeSet PAL = getAttributes(Record[OpNum++]); + unsigned CCInfo = Record[OpNum++]; + BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]); + BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]); + + FunctionType *FTy = nullptr; + if (CCInfo >> 13 & 1 && + !(FTy = dyn_cast(getTypeByID(Record[OpNum++])))) + return Error("Explicit invoke type is not a function type"); - unsigned OpNum = 4; Value *Callee; if (getValueTypePair(Record, OpNum, NextValueNo, Callee)) return Error("Invalid record"); PointerType *CalleeTy = dyn_cast(Callee->getType()); - FunctionType *FTy = !CalleeTy ? nullptr : - dyn_cast(CalleeTy->getElementType()); - - // Check that the right number of fixed parameters are here. - if (!FTy || !NormalBB || !UnwindBB || - Record.size() < OpNum+FTy->getNumParams()) - return Error("Invalid record"); + if (!CalleeTy) + return Error("Callee is not a pointer"); + if (!FTy) { + FTy = dyn_cast(CalleeTy->getElementType()); + if (!FTy) + return Error("Callee is not of pointer to function type"); + } else if (CalleeTy->getElementType() != FTy) + return Error("Explicit invoke type does not match pointee type of " + "callee operand"); + if (Record.size() < FTy->getNumParams() + OpNum) + return Error("Insufficient operands to call"); SmallVector Ops; for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) { @@ -3905,8 +3914,8 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops); InstructionList.push_back(I); - cast(I)->setCallingConv( - static_cast(CCInfo)); + cast(I) + ->setCallingConv(static_cast(~(1U << 13) & CCInfo)); cast(I)->setAttributes(PAL); break; } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index c4b31ff..52a5d48 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1790,15 +1790,15 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, case Instruction::Invoke: { const InvokeInst *II = cast(&I); - const Value *Callee(II->getCalledValue()); - PointerType *PTy = cast(Callee->getType()); - FunctionType *FTy = cast(PTy->getElementType()); + const Value *Callee = II->getCalledValue(); + FunctionType *FTy = II->getFunctionType(); Code = bitc::FUNC_CODE_INST_INVOKE; Vals.push_back(VE.getAttributeID(II->getAttributes())); - Vals.push_back(II->getCallingConv()); + Vals.push_back(II->getCallingConv() | 1 << 13); Vals.push_back(VE.getValueID(II->getNormalDest())); Vals.push_back(VE.getValueID(II->getUnwindDest())); + Vals.push_back(VE.getTypeID(FTy)); PushValueAndType(Callee, InstID, Vals, VE); // Emit value #'s for the fixed parameters. diff --git a/llvm/test/Bitcode/Inputs/invalid-invoke-mismatched-explicit-type.bc b/llvm/test/Bitcode/Inputs/invalid-invoke-mismatched-explicit-type.bc new file mode 100644 index 0000000..bce88529 Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-invoke-mismatched-explicit-type.bc differ diff --git a/llvm/test/Bitcode/Inputs/invalid-invoke-non-function-explicit-type.bc b/llvm/test/Bitcode/Inputs/invalid-invoke-non-function-explicit-type.bc new file mode 100644 index 0000000..d7810bb Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-invoke-non-function-explicit-type.bc differ diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index f2271e8..0bed40b 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -22,6 +22,10 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-call-mismatched-explicit-typ RUN: FileCheck --check-prefix=MISMATCHED-EXPLICIT-CALL %s RUN: not llvm-dis -disable-output %p/Inputs/invalid-call-non-function-explicit-type.bc 2>&1 | \ RUN: FileCheck --check-prefix=NON-FUNCTION-EXPLICIT-CALL %s +RUN: not llvm-dis -disable-output %p/Inputs/invalid-invoke-mismatched-explicit-type.bc 2>&1 | \ +RUN: FileCheck --check-prefix=MISMATCHED-EXPLICIT-INVOKE %s +RUN: not llvm-dis -disable-output %p/Inputs/invalid-invoke-non-function-explicit-type.bc 2>&1 | \ +RUN: FileCheck --check-prefix=NON-FUNCTION-EXPLICIT-INVOKE %s INVALID-ENCODING: Invalid encoding BAD-ABBREV: Abbreviation starts with an Array or a Blob @@ -35,6 +39,8 @@ MISMATCHED-EXPLICIT-LOAD: Explicit load type does not match pointee type of poin MISMATCHED-EXPLICIT-GEP-OPERATOR: Explicit gep operator type does not match pointee type of pointer operand MISMATCHED-EXPLICIT-CALL: Explicit call type does not match pointee type of callee operand NON-FUNCTION-EXPLICIT-CALL: Explicit call type is not a function type +MISMATCHED-EXPLICIT-INVOKE: Explicit invoke type does not match pointee type of callee operand +NON-FUNCTION-EXPLICIT-INVOKE: Explicit invoke type is not a function type RUN: not llvm-dis -disable-output %p/Inputs/invalid-extractval-array-idx.bc 2>&1 | \ RUN: FileCheck --check-prefix=EXTRACT-ARRAY %s