<div dir="ltr">Okey, setCalledFunction is useful. But I have a problem since my "a", "b", "c" are functions from libc, not my defined ones in the module.<div><br></div><div><div>if (CallInst *call_inst = dyn_cast<CallInst>(&I)) {</div><div>          </div><div>          Function *fn = call_inst->getCalledFunction();</div><div>          if (fn->getName() == "a") {</div><div>            ValueToValueMapTy map;<br></div><div>            FN = CloneFunction(fn, map, nullptr);</div><div>            FN->setName("c");</div><div>            call_inst->setCalledFunction(FN);</div><div>          }</div><div>          ...</div><div>}</div></div><div><br></div><div><br></div><div>I get "Assertion `!NodePtr->isKnownSentinel()' failed."</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-24 1:19 GMT+01:00 <a href="http://mayuyu.io">mayuyu.io</a> <span dir="ltr"><<a href="mailto:admin@mayuyu.io" target="_blank">admin@mayuyu.io</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
You are probably calling setName() on the called Function, which in-turned renamed the called Function instead of replacing the called function.<br>
Depending on your use-case, if you are certain that you only need to modify CallInsts, then you could simply call CallInst::setCalledFunction , otherwise it’s probably wiser to use CallSite as a wrapper for both CallInst and InvokeInst. Do note, however, that no matter which solution you end up using, you’ll need to update the FunctionType as well<br>
<span class="im HOEnZb">Zhang<br>
<br>
> On 23 Mar 2018, at 23:07, Dávid Bolvanský via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
</span><div class="HOEnZb"><div class="h5">> Hello,<br>
><br>
> In my module I have functions:<br>
><br>
> a<br>
> b<br>
> c<br>
> f3 calls "a"<br>
> f2 calls "a"<br>
> f1 calls "b"<br>
><br>
> I would like to modify a CallInst in the f2. Now it calls "a", but I want changed it to "c".<br>
><br>
> When loop over the instructions of the  f2, I can get a CallInst to be modified, then I use "setName" to changed it to "c".<br>
><br>
><br>
> Problem is, since references are updated, "a" is changed to "c" even in f1.<br>
><br>
> Any solution?<br>
><br>
> Thanks<br>
</div></div><div class="HOEnZb"><div class="h5">> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
</div></div></blockquote></div><br></div>