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

Marc Claesen claesenm at gmail.com
Wed Nov 11 09:19:07 PST 2009


> CreateAlloca(Type) returns an object of type Type*, the memory that
> can hold an object of type Type. You probably don't want to be
> creating allocas just before calling the function since 1) if that
> call winds up in a loop they'll grow your stack frame without bound,
> and 2) the memory they point to is initially uninitialized. Where did
> the tutorial tell you to do that?

I used CreateAllocA(Type) because I assumed that was the correct way to 
create a variable of a given type.

What I'm trying to do is create new variables of the types required by a 
function and then call the function, so it's quite simple ... I just 
don't know how to initialise correctly by the looks of it. What function 
should I use if not CreateAllocA(Type)?

Thanks in advance,

Marc

Jeffrey Yasskin wrote:
> CreateAlloca(Type) returns an object of type Type*, the memory that
> can hold an object of type Type. You probably don't want to be
> creating allocas just before calling the function since 1) if that
> call winds up in a loop they'll grow your stack frame without bound,
> and 2) the memory they point to is initially uninitialized. Where did
> the tutorial tell you to do that?
>
> In general, when I hit one of those assertions, I gdb to it, use "p
> f->dump()" to see the types of the function's arguments, and use "p
> Params[i]->dump()" to see the parameter with the bad type.
>
> On Wed, Nov 11, 2009 at 7:22 AM, Marc Claesen <claesenm at gmail.com> wrote:
>   
>> 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
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>     
>
>   




More information about the llvm-dev mailing list