[llvm-dev] Insert CallInst within a function passing same parameters of the calling function.

Simone Atzeni via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 1 12:51:27 PST 2016


Hi,

supposing I have a function “foo” like the following:

int foo(int a, int b) {

...
...
}

I want to insert int the LLVM IR a call instructions to a function “bar” that requires the same parameters of foo.
So my function foo will become:

int foo(int a, int b) {
  bar(a,b);
  …
  ...
}

I am using the following code:

bool ThreadSanitizer::runOnFunction(Function &F) {  
    ValueToValueMapTy VMap;                                                                                                   
    Function *new_function = CloneFunction(&F, VMap, false);                                                            
    new_function->setName(functionName + “_newfunction");                                                               
    F.getParent()->getFunctionList().push_back(new_function);                                                                                                  

    Function::ArgumentListType::iterator it = F.getArgumentList().begin();                                                    
    Function::ArgumentListType::iterator end = F.getArgumentList().end();                                                     

    std::vector<Value*> args;   
    while (it != end) {                                                                                                       
      Argument *Args = &(*it);                                                                                                
      args.push_back(Args);                                                                                                   
      it++;                                                                                                                   
    }                                                                                                                         
                                                                                                                              
    CallInst::Create(new_function->getFunctionType(), new_function, args, functionName + "__swordomp__", &F.getEntryBlock().front());                                                                                                          
}

but I am getting the following error:

void llvm::Value::setNameImpl(const llvm::Twine&): Assertion `!getType()->isVoidTy() && "Cannot assign a name to void values!"' failed.

How should I fix it?

Thanks.
Best,
Simone


More information about the llvm-dev mailing list