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

Kevin Hu via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 1 15:09:13 PST 2016


Howdy Simone,

If my poor memory still serves me correctly, the NameStr parameter here is
the name for the Value class that accepts the return value of the CallInst,
not the name for the CallInst itself. So when the function of the CallInst
is void, it's illegal to assign the return value to any names

Correct me if I'm wrong.

Also I do wish LLVM documentations could give more details on its function
parameters. It could help newcomers a lot.

Regards,
Kevin

On Tue, Mar 1, 2016 at 4:24 PM Simone Atzeni via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160301/f96630f0/attachment-0001.html>


More information about the llvm-dev mailing list