<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 9/8/15 11:16 AM, Christian Convey
via llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAPfS4ZxNMGuPGS0TTv2UuvqjyqVyKQ6HwvSE8NSZuE7amHPcwQ@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr"><span>I was wondering if someone could explain why </span>CallInst::getCalledFunc<span> behaves
the way it does.</span>
<div><br>
</div>
<div>For simple, direct call instructions in my IR, that method
behaves just as one would expect.</div>
<div><br>
</div>
<div>However, for instructions like this:</div>
<div><br>
</div>
<div>
<blockquote class="gmail_quote">%25 = call i32
(%struct._IO_FILE*, ...)* bitcast (i32 (...)* @close to i32
(%struct._IO_FILE*, ...)*)(%struct._IO_FILE* %24), !dbg !695</blockquote>
<div><br>
</div>
<div>getCalledFunc returns null.</div>
<div><br>
</div>
<div>I know <span>getCalledFunc</span> is <a
moz-do-not-send="true"
href="http://llvm.org/docs/doxygen/html/classllvm_1_1CallInst.html#a0bcd4131e1a1d92215f5385b4e16cd2e"
target="_blank">expected to return null</a> on indirect
calls, but I would have thought naming the callee via a
constant expression like the one here would be considered a
direct call.</div>
</div>
</div>
</blockquote>
<br>
The getCalledFunc() method is not very sophisticated. It turns NULL
if the called value is not trivially a function constant.<br>
<br>
I'm not sure for the reasoning behind this. My best guess is that a
constant expression could do all sorts of interesting things. For
example, a constant expression can select one of several values or
pull a value out of an array using a constant expression GEP.<br>
<br>
You'll need to do what SAFECode does; use
getCalledValue()->stripPointerCasts() to get the called value and
remove any casts that stand between you and the function value.
It's inconvenient, but it works.<br>
<br>
Alternatively, you could see if the CallSite() class provides a
smarter method of getting the called function, but I'm not sure if
it has such a method.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<blockquote
cite="mid:CAPfS4ZxNMGuPGS0TTv2UuvqjyqVyKQ6HwvSE8NSZuE7amHPcwQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Thanks,</div>
<div>Christian</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>