Strange error using CallInst constructor

Hi,

This is probably more of a standard C++ question instead of an actual LLVM question, but here it goes anyway. I'm trying to invoke the following constructor:
CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
const Twine &NameStr, BasicBlock *InsertAtEnd);

My code is:

using namespace llvm;
void replaceByClone(Function *f, CallInst *I){
Function *clone = CloneFunction(f);
BasicBlock::iterator ii(I);
ReplaceInstWithInst(I->getParent()->getInstList(),ii,CallInst(clone,clone->arg_begin(),clone->arg_end()));
}

Compiling generates the following error:
error: no matching function for call to ‘llvm::CallInst::CallInst(llvm::Function*&, llvm::ilist_iterator<llvm::Argument>, llvm::ilist_iterator<llvm::Argument>)’
/media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:985: note: candidates are: llvm::CallInst::CallInst(llvm::Value*, const llvm::Twine&, llvm::BasicBlock*)
/media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:984: note: llvm::CallInst::CallInst(llvm::Value*, const llvm::Twine&, llvm::Instruction*)
/media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:982: note: llvm::CallInst::CallInst(llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::BasicBlock*)
/media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:980: note: llvm::CallInst::CallInst(llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::Instruction*)
/media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:940: note: llvm::CallInst::CallInst(const llvm::CallInst&)

Apparantly, clone is not of type Function* but of type Function*& ... I have no idea why this is. I've checked the LLVM source for similar invocations and they all seem to do what my code does. Any ideas?

Thanks in advance,
Marc Claesen

You're trying to invoke a 5-argument constructor with 3 arguments.
Ain't gonna work.

CallInst() is private, so even if you found the right overload, it
wouldn't compile. To build LLVM IR objects, you generally call their
static Foo::Create() function, which does have an overload taking your
parameters.

It doesn't really matter that clone is of type Function*&. It's true,
and will let you pass it to a parameter of that type, but it'll also
match a parameter of type Function*.

Please keep replies on the list.

Now you've missed "InputIterator must be a random-access iterator
pointing to contiguous storage (e.g. a std::vector<>::iterator).
Checks are made for random-accessness but not for contiguous storage
as that would incur runtime overhead." from CallInst's constructor
(although that comment should be on Create()). Function::arg_iterator
isn't random-access.

You probably also want to pull the arguments out of the old CallInst,
not out of the parameters of the new function. The old CallInst that
you're replacing can't see the arguments of a function you've just
created.