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

Óscar Fuentes ofv at wanadoo.es
Wed Nov 11 10:43:59 PST 2009


[Please use Reply to All for sending your message to the ml too]

Marc Claesen <claesenm at gmail.com> writes:

>> Another issue is that I don't see in your code the _values_ you want to
>> pass to the called function. Apparently you already have the function
>> declaration (Function *f) but you are creating a call to that function,
>> and you need the actual arguments (not the argument types):
>
> That's exactly the problem. I'm trying to initialise values of the
> appropriate types as required by a given function and pass those. What
> I'm looking for is the appropriate instructions to initialise a
> variable of a given type to it's type's default value. I realise this
> program will generate useless function calls but it's part of a binary
> obfuscation chain.

In LLVM there is no such a thing as a type default value. Maybe that
concept exists on your language.

Creating allocas is not the solution, as the alloca is just
uninitialized space on the stack.

Suppossing that the function parameters simple enough, like integral or
floating point types, and the "default value" is zero, something like
this will do (untested):

  std::vector<Value*> args;
  IRBuilder<> builder(bb,pos);
  for(Function::arg_iterator argit = 
      f->arg_begin();argit!=f->arg_end();
      argit++)
  {
      Value *arg = Constant::getNullValue(argit->getType());
      args.push_back(arg);
  }
  builder.CreateCall(f,args.begin(),args.end());

If your arguments are something more fancy, you have more work ahead
(for following the platform/language ABI, etc).

-- 
Óscar




More information about the llvm-dev mailing list