<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 11/12/15 10:27 PM, Shen Liu via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAHxbscvDXEeW6Ntasmq-mFABMjpC_D648nBpxYjvjoBP95=jSw@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<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>
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
cite="mid:CAHxbscvDXEeW6Ntasmq-mFABMjpC_D648nBpxYjvjoBP95=jSw@mail.gmail.com"
type="cite">
<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 class=""> </span> u = 2 * quantum_frand() - 1;</div>
<div><span class=""> </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 class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>