From fa3e91242fada931ccb96468ac4c93ca151d64dc Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 9 Apr 2007 18:00:57 +0000 Subject: [PATCH] For PR1146: * Add ParamAttrs to InvokeInst class too. * Make sure all initializes of ParamAttrs in CallInst and InvokeInst are 0 * Destruct the ParamAttrs in Call/Invoke destructors to avoid memory leaks. This will change when ParamAttrsList is uniquified but needs to be correct until then. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35824 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instructions.h | 19 ++++++++++++++++--- lib/VMCore/Instructions.cpp | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index a25dd128ef2..8f3b24a1e6f 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -737,10 +737,11 @@ public: SubclassData = (SubclassData & 1) | (CC << 1); } - /// Obtains a constant pointer to the ParamAttrsList object which holds the - /// parameter attributes information, if any. + /// Obtains a pointer to the ParamAttrsList object which holds the + /// parameter attributes information, if any. + /// @returns 0 if no attributes have been set. /// @brief Get the parameter attributes. - const ParamAttrsList *getParamAttrs() const { return ParamAttrs; } + ParamAttrsList *getParamAttrs() const { return ParamAttrs; } /// Sets the parameter attributes for this CallInst. To construct a /// ParamAttrsList, see ParameterAttributes.h @@ -1445,6 +1446,7 @@ private: /// calling convention of the call. /// class InvokeInst : public TerminatorInst { + ParamAttrsList *ParamAttrs; InvokeInst(const InvokeInst &BI); void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, Value* const *Args, unsigned NumArgs); @@ -1466,6 +1468,17 @@ public: SubclassData = CC; } + /// Obtains a pointer to the ParamAttrsList object which holds the + /// parameter attributes information, if any. + /// @returns 0 if no attributes have been set. + /// @brief Get the parameter attributes. + ParamAttrsList *getParamAttrs() const { return ParamAttrs; } + + /// Sets the parameter attributes for this InvokeInst. To construct a + /// ParamAttrsList, see ParameterAttributes.h + /// @brief Set the parameter attributes. + void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; } + /// getCalledFunction - Return the function called, or null if this is an /// indirect function invocation. /// diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index c09ec3ce217..f9aa3e7b2d2 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -17,6 +17,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/Instructions.h" +#include "llvm/ParameterAttributes.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/ConstantRange.h" using namespace llvm; @@ -185,6 +186,7 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { CallInst::~CallInst() { delete [] OperandList; + delete ParamAttrs; // FIXME: ParamAttrsList should be uniqued! } void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) { @@ -337,6 +339,7 @@ CallInst::CallInst(Value *Func, const std::string &Name, CallInst::CallInst(const CallInst &CI) : Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()], CI.getNumOperands()) { + ParamAttrs = 0; SubclassData = CI.SubclassData; Use *OL = OperandList; Use *InOL = CI.OperandList; @@ -351,10 +354,12 @@ CallInst::CallInst(const CallInst &CI) InvokeInst::~InvokeInst() { delete [] OperandList; + delete ParamAttrs; // FIXME: ParamAttrsList should be uniqued! } void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, Value* const *Args, unsigned NumArgs) { + ParamAttrs = 0; NumOperands = 3+NumArgs; Use *OL = OperandList = new Use[3+NumArgs]; OL[0].init(Fn, this); @@ -402,6 +407,7 @@ InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal, InvokeInst::InvokeInst(const InvokeInst &II) : TerminatorInst(II.getType(), Instruction::Invoke, new Use[II.getNumOperands()], II.getNumOperands()) { + ParamAttrs = 0; SubclassData = II.SubclassData; Use *OL = OperandList, *InOL = II.OperandList; for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i) -- 2.34.1