<div dir="ltr"><div><div>Dear Ashutosh,<br></div><div><br></div><div>Thank you, I can handle some indirect callSites by getFunction() of InvokInst and CallInst.</div><div><br></div><div>However, when I am handling C++ programs, I found the calls of member functions are converted</div><div>to some strange indirect calls. For example:</div><div><br></div><div>table->truncate(sysTransaction); // from mysql</div><div><br></div><div>are translated to the next complex llvm IR:</div><div><br></div><div>_ZN8Database20getSystemTransactionEv.exit: ; preds = %bb33</div><div> call void @llvm.dbg.value(metadata %class.Transaction.553* %tmp36, i64 0, metadata !7310, metadata !53545), !dbg !69981</div><div> %tmp37 = bitcast %class.Table.543* %table to void (%class.Table.543*, %class.Transaction.553*)***, !dbg !69982</div><div> %tmp38 = load void (%class.Table.543*, %class.Transaction.553*)*** %tmp37, align 8, !dbg !69982, !tbaa !53550</div><div> %tmp39 = getelementptr inbounds void (%class.Table.543*, %class.Transaction.553*)** %tmp38, i64 5, !dbg !69982</div><div> %tmp40 = load void (%class.Table.543*, %class.Transaction.553*)** %tmp39, align 8, !dbg !69982</div><div> invoke void %tmp40(%class.Table.543* %table, %class.Transaction.553* %tmp36)</div><div> to label %bb41 unwind label %bb72, !dbg !69982</div></div><div><br></div><div>and thus I cannot find the called function "truncate" from "invoke void %tmp40(...)", what should I do?</div><div>I didn't analysis C++ code with llvm, does all the function calls through objects are translated to such complex indirect calls?</div><div>If so, how can I dereference such functions? Thanks!</div><div><br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><br>--------------------------------------------<br>Qiuping Yi<br>Institute Of Software<br>Chinese Academy of Sciences</div></div>
<br><div class="gmail_quote">On Tue, Jan 19, 2016 at 8:23 PM, Nema, Ashutosh <span dir="ltr"><<a href="mailto:Ashutosh.Nema@amd.com" target="_blank">Ashutosh.Nema@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">You will see NULL for indirect callSite.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">May need to add additional checks for this possibility.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Ashutosh<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Qiuping Yi via llvm-dev<br>
<b>Sent:</b> Tuesday, January 19, 2016 5:35 PM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [llvm-dev] Why getFunction() of CallGraphNode return NULL function?<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Hi all,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">I want to find all the called functions in each function, thus I iterate the calledFunctions of each CallGraphNode in CallGraph as follow:<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">for (CallGraph::iterator it = CG->begin(); it != CG->end(); ++it) {<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> CallGraphNode* node = it->second;<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> for (CallGraphNode::iterator it2 = node->begin(); it2 != node->end(); ++it2) {<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> Function* calledFunc = it2->second=>getFunction();<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> cerr <<</span><span style="font-size:9.5pt;font-family:Calibri,sans-serif"> </span><span style="font-size:9.5pt">”function: “ << calledFunc->getName().str() <<"\n"; <b>// crash some times</b><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> ... ...<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> ... ...<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">}<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">I found that some time "calledFunc" is NULL function and thus the output crash. I don't known why? If the before code is wrong, so what is the correct method for get all the called functions?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">I use LLVM 3.6. Thank you all in advance.<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><br>
--------------------------------------------<br>
Qiuping Yi<br>
Institute Of Software<br>
Chinese Academy of Sciences<u></u><u></u></p>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br></div></div>