[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 14:23:52 PST 2016
Looks like I found the solution.
When I call CallInst::Create, the param NameStr needs to be an empty string for void functions.
I thought that value was the name of the function I want to call, but apparently is not.
Why is that then?
Thanks.
Best,
Simone
> On Mar 1, 2016, at 13:51, Simone Atzeni <simone.at at gmail.com> wrote:
>
> 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