<div dir="ltr">Appreciate your advice, John! It works well as you said, thanks very much!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 13, 2015 at 8:44 AM, John Criswell <span dir="ltr"><<a href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<div>On 11/12/15 10:27 PM, Shen Liu via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi all,
<div><br>
</div>
<div>Usually if we want to get the called Function we can
directly use CallInst->getCalledFunction(), however, today
i encounter an unusual CallInst as follows:</div>
<div><br>
</div>
<div> %call11 = call double (...)* bitcast (double ()*
@quantum_frand to double (...)*)()<br>
</div>
</div>
</blockquote>
<br></span>
As others have noted, Function::getCalledFunction() is returning
null because the function that is being called is first casted. For
some reason, Function::getCalledFunction() does not strip off
pointer casts on its first argument.<br>
<br>
However, you can do that easily. Just use:<br>
<br>
Function * calledFunc =
dyn_cast<Function>(CallInst->getCalledValue()->stripPointerCasts())<br>
<br>
If calledFunc is non-zero, it's a pointer to the called function.
Otherwise, you have an indirect call.<br>
<br>
As an aside, note that indirect calls are sometimes the result of a
select instruction that picks between one of two functions. It's
therefore worth checking to see if the called value is a SelectInst
and, if it is, see if both operands to the SelectInst are Functions.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<blockquote type="cite"><span class="">
<div dir="ltr">
<div><br>
</div>
<div>the original C source involve type cast:</div>
<div><br>
</div>
<div>float u,v;<br>
</div>
<div>extern double quantum_frand();<br>
</div>
<div>
<div><span> </span> u = 2 * quantum_frand() - 1;</div>
<div><span> </span> v = 2 * quantum_frand() - 1;</div>
</div>
<div><br>
</div>
<div>In this case, CallInst->getCalledFunction() returns a
nullptr unusually, I printed out the getOperand(0) and found
the operand is the whole thing of "double (...)* bitcast
(double ()* @quantum_frand to double (...)*)()". Any member
function calling on that fails so i don't know whether there
is an efficient way to exactly get the called function
@quantum_frand(...) here? Thanks!</div>
<div><br>
</div>
<div><br>
</div>
<div>Best regards,</div>
<div><br>
</div>
<div>Shen</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</span><span class=""><pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
<br>
<pre cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
</font></span></div>
</blockquote></div><br></div>