From 3e80709ef9cedf04f5001d02b26921c9f0d43d5d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 13 May 2015 18:35:26 +0000 Subject: [PATCH] [opaque pointer type] Pass the explicit function type down to the instruction constructor when parsing invoke instructions llvm-svn: 237273 --- llvm/include/llvm/IR/Instructions.h | 51 ++++++++++++++++++++++++++----------- llvm/lib/AsmParser/LLParser.cpp | 2 +- llvm/lib/IR/Instructions.cpp | 7 ++--- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index e8e7069..776abb2 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -3090,15 +3090,30 @@ class InvokeInst : public TerminatorInst { FunctionType *FTy; InvokeInst(const InvokeInst &BI); void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, - ArrayRef Args, const Twine &NameStr); + ArrayRef Args, const Twine &NameStr) { + init(cast( + cast(Func->getType())->getElementType()), + Func, IfNormal, IfException, Args, NameStr); + } + void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal, + BasicBlock *IfException, ArrayRef Args, + const Twine &NameStr); /// Construct an InvokeInst given a range of arguments. /// /// \brief Construct an InvokeInst from a range of arguments inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, unsigned Values, - const Twine &NameStr, Instruction *InsertBefore); - + const Twine &NameStr, Instruction *InsertBefore) + : InvokeInst(cast( + cast(Func->getType())->getElementType()), + Func, IfNormal, IfException, Args, Values, NameStr, + InsertBefore) {} + + inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, + BasicBlock *IfException, ArrayRef Args, + unsigned Values, const Twine &NameStr, + Instruction *InsertBefore); /// Construct an InvokeInst given a range of arguments. /// /// \brief Construct an InvokeInst from a range of arguments @@ -3112,9 +3127,17 @@ public: BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, const Twine &NameStr = "", Instruction *InsertBefore = nullptr) { + return Create(cast( + cast(Func->getType())->getElementType()), + Func, IfNormal, IfException, Args, NameStr, InsertBefore); + } + static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, + BasicBlock *IfException, ArrayRef Args, + const Twine &NameStr = "", + Instruction *InsertBefore = nullptr) { unsigned Values = unsigned(Args.size()) + 3; - return new(Values) InvokeInst(Func, IfNormal, IfException, Args, - Values, NameStr, InsertBefore); + return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, + Values, NameStr, InsertBefore); } static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, @@ -3357,16 +3380,14 @@ template <> struct OperandTraits : public VariadicOperandTraits { }; -InvokeInst::InvokeInst(Value *Func, - BasicBlock *IfNormal, BasicBlock *IfException, - ArrayRef Args, unsigned Values, - const Twine &NameStr, Instruction *InsertBefore) - : TerminatorInst(cast(cast(Func->getType()) - ->getElementType())->getReturnType(), - Instruction::Invoke, - OperandTraits::op_end(this) - Values, - Values, InsertBefore) { - init(Func, IfNormal, IfException, Args, NameStr); +InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, + BasicBlock *IfException, ArrayRef Args, + unsigned Values, const Twine &NameStr, + Instruction *InsertBefore) + : TerminatorInst(Ty->getReturnType(), Instruction::Invoke, + OperandTraits::op_end(this) - Values, Values, + InsertBefore) { + init(Ty, Func, IfNormal, IfException, Args, NameStr); } InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index e69fa38..398292c 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -4826,7 +4826,7 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) { // Finish off the Attribute and check them AttributeSet PAL = AttributeSet::get(Context, Attrs); - InvokeInst *II = InvokeInst::Create(Callee, NormalBB, UnwindBB, Args); + InvokeInst *II = InvokeInst::Create(Ty, Callee, NormalBB, UnwindBB, Args); II->setCallingConv(CC); II->setAttributes(PAL); ForwardRefAttrGroups[II] = FwdRefAttrGrps; diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 3e68138..3a32be5 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -537,9 +537,10 @@ Instruction* CallInst::CreateFree(Value* Source, BasicBlock *InsertAtEnd) { // InvokeInst Implementation //===----------------------------------------------------------------------===// -void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, - ArrayRef Args, const Twine &NameStr) { - FTy = cast(cast(Fn->getType())->getElementType()); +void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal, + BasicBlock *IfException, ArrayRef Args, + const Twine &NameStr) { + this->FTy = FTy; assert(NumOperands == 3 + Args.size() && "NumOperands not set up?"); Op<-3>() = Fn; -- 2.7.4