[LLVMdev] Adding function call in LLVM IR using IRBuilder causes assertion error

Marc Claesen claesenm at gmail.com
Wed Nov 11 07:22:56 PST 2009


Hi,

I'm trying to add function calls in the LLVM IR using the IRBuilder 
class. I've read both tutorials about functions but I still get 
assertion errors. I allocate memory for all function arguments and pass 
them as explained in the tutorial.

My code is (this function is supposed to add a call to f in bb at pos):
void addCallSite(Function *f, BasicBlock *bb, BasicBlock::iterator pos) {
  std::vector<Value*> args;
  IRBuilder<> builder(bb,pos);
  for(Function::arg_iterator argit = 
f->arg_begin();argit!=f->arg_end();argit++){
      AllocaInst* allocInst = builder.CreateAlloca(argit->getType());
      args.push_back(allocInst);
  }
  builder.CreateCall(f,args.begin(),args.end());
}

This seems to work for functions without parameters (eg. int foo()), but 
once a function has a parameter I get the following assertion error:
<llvmpath>/lib/VMCore/Instructions.cpp:297: void 
llvm::CallInst::init(llvm::Value*, llvm::Value* const*, unsigned int): 
Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == 
Params[i]->getType()) && "Calling a function with a bad signature!"' failed.

I've checked everything I can think of and it all seems correct to me 
... Any help would be greatly appreciated!

Thanks in advance,

Marc Claesen



More information about the llvm-dev mailing list