mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-24 08:24:33 +00:00
[opaque pointer type] bitcode: add explicit callee type to invoke instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235735 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -3863,24 +3863,33 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
|
// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
|
||||||
if (Record.size() < 4)
|
if (Record.size() < 4)
|
||||||
return Error("Invalid record");
|
return Error("Invalid record");
|
||||||
AttributeSet PAL = getAttributes(Record[0]);
|
unsigned OpNum = 0;
|
||||||
unsigned CCInfo = Record[1];
|
AttributeSet PAL = getAttributes(Record[OpNum++]);
|
||||||
BasicBlock *NormalBB = getBasicBlock(Record[2]);
|
unsigned CCInfo = Record[OpNum++];
|
||||||
BasicBlock *UnwindBB = getBasicBlock(Record[3]);
|
BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]);
|
||||||
|
BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]);
|
||||||
|
|
||||||
|
FunctionType *FTy = nullptr;
|
||||||
|
if (CCInfo >> 13 & 1 &&
|
||||||
|
!(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
|
||||||
|
return Error("Explicit invoke type is not a function type");
|
||||||
|
|
||||||
unsigned OpNum = 4;
|
|
||||||
Value *Callee;
|
Value *Callee;
|
||||||
if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
|
if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
|
||||||
return Error("Invalid record");
|
return Error("Invalid record");
|
||||||
|
|
||||||
PointerType *CalleeTy = dyn_cast<PointerType>(Callee->getType());
|
PointerType *CalleeTy = dyn_cast<PointerType>(Callee->getType());
|
||||||
FunctionType *FTy = !CalleeTy ? nullptr :
|
if (!CalleeTy)
|
||||||
dyn_cast<FunctionType>(CalleeTy->getElementType());
|
return Error("Callee is not a pointer");
|
||||||
|
if (!FTy) {
|
||||||
// Check that the right number of fixed parameters are here.
|
FTy = dyn_cast<FunctionType>(CalleeTy->getElementType());
|
||||||
if (!FTy || !NormalBB || !UnwindBB ||
|
if (!FTy)
|
||||||
Record.size() < OpNum+FTy->getNumParams())
|
return Error("Callee is not of pointer to function type");
|
||||||
return Error("Invalid record");
|
} 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<Value*, 16> Ops;
|
SmallVector<Value*, 16> Ops;
|
||||||
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
|
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);
|
I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops);
|
||||||
InstructionList.push_back(I);
|
InstructionList.push_back(I);
|
||||||
cast<InvokeInst>(I)->setCallingConv(
|
cast<InvokeInst>(I)
|
||||||
static_cast<CallingConv::ID>(CCInfo));
|
->setCallingConv(static_cast<CallingConv::ID>(~(1U << 13) & CCInfo));
|
||||||
cast<InvokeInst>(I)->setAttributes(PAL);
|
cast<InvokeInst>(I)->setAttributes(PAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1790,15 +1790,15 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
|
|||||||
|
|
||||||
case Instruction::Invoke: {
|
case Instruction::Invoke: {
|
||||||
const InvokeInst *II = cast<InvokeInst>(&I);
|
const InvokeInst *II = cast<InvokeInst>(&I);
|
||||||
const Value *Callee(II->getCalledValue());
|
const Value *Callee = II->getCalledValue();
|
||||||
PointerType *PTy = cast<PointerType>(Callee->getType());
|
FunctionType *FTy = II->getFunctionType();
|
||||||
FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
|
|
||||||
Code = bitc::FUNC_CODE_INST_INVOKE;
|
Code = bitc::FUNC_CODE_INST_INVOKE;
|
||||||
|
|
||||||
Vals.push_back(VE.getAttributeID(II->getAttributes()));
|
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->getNormalDest()));
|
||||||
Vals.push_back(VE.getValueID(II->getUnwindDest()));
|
Vals.push_back(VE.getValueID(II->getUnwindDest()));
|
||||||
|
Vals.push_back(VE.getTypeID(FTy));
|
||||||
PushValueAndType(Callee, InstID, Vals, VE);
|
PushValueAndType(Callee, InstID, Vals, VE);
|
||||||
|
|
||||||
// Emit value #'s for the fixed parameters.
|
// Emit value #'s for the fixed parameters.
|
||||||
|
BIN
test/Bitcode/Inputs/invalid-invoke-mismatched-explicit-type.bc
Normal file
BIN
test/Bitcode/Inputs/invalid-invoke-mismatched-explicit-type.bc
Normal file
Binary file not shown.
BIN
test/Bitcode/Inputs/invalid-invoke-non-function-explicit-type.bc
Normal file
BIN
test/Bitcode/Inputs/invalid-invoke-non-function-explicit-type.bc
Normal file
Binary file not shown.
@ -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: 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: 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: 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
|
INVALID-ENCODING: Invalid encoding
|
||||||
BAD-ABBREV: Abbreviation starts with an Array or a Blob
|
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-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
|
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
|
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: not llvm-dis -disable-output %p/Inputs/invalid-extractval-array-idx.bc 2>&1 | \
|
||||||
RUN: FileCheck --check-prefix=EXTRACT-ARRAY %s
|
RUN: FileCheck --check-prefix=EXTRACT-ARRAY %s
|
||||||
|
Reference in New Issue
Block a user