Hi all,<div><br></div><div>I just start to learn llvm. I am trying to get the operand's name of some instruction that invokes a function field of a struct. While,  I found in the result that there is a sequence number attached to the function field name. Below is an example:</div>
<div><br></div><div>/******source code t2.c*******/</div><div><p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(57,51,255)"><span style="color:#931a68">#include</span><span style="color:#000000"> </span><stdio.h></p>

<p style="margin:0px;font-size:13px;font-family:Monaco;min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> F(){printf(<span style="color:rgb(57,51,255)">"F\n"</span>);} </p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> E(){printf(<span style="color:rgb(57,51,255)">"E\n"</span>);} </p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> D(){printf(<span style="color:rgb(57,51,255)">"D\n"</span>);}</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> C(){D();E();printf(<span style="color:rgb(57,51,255)">"C\n"</span>);}</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> B(){C();printf(<span style="color:rgb(57,51,255)">"C\n"</span>);}</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> A(){B();printf(<span style="color:rgb(57,51,255)">"A\n"</span>);} </p>
<p style="margin:0px;font-size:13px;font-family:Monaco;min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">int</span> main(){</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(147,26,104)">struct<span style="color:#000000"> s{</span></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(147,26,104)">int<span style="color:#000000"> </span><span style="color:#0326cc">vvv</span><span style="color:#000000">;</span></p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> (*<span style="color:#0326cc">ff</span>)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> (*<span style="color:#0326cc">tt</span>)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(3,38,204)"><span style="color:#931a68">int</span><span style="color:#000000"> </span>value<span style="color:#000000"> ;</span></p>
<p style="margin:0px;font-size:13px;font-family:Monaco">}sss;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> (*ppp)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"><span style="color:#931a68">void</span> (*kkk)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">A();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">tt</span> = &A;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">tt</span>();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">ff</span> = &C;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">ff</span>();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">tt</span> = &F;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">sss.<span style="color:#0326cc">tt</span>();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco">kkk = &B;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">ppp = &C;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">(*ppp)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">(*kkk)();</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">}</p><p style="margin:0px;font-size:13px;font-family:Monaco"><br></p><p style="margin:0px;font-size:13px;font-family:Monaco">I use the following command to generate the .bc file:</p>
<p style="margin:0px;font-size:13px;font-family:Monaco">clang -O0 -c -emit-llvm t2.c -o t2.bc</p><p style="margin:0px;font-size:13px;font-family:Monaco"><br></p><p style="margin:0px;font-size:13px;font-family:Monaco">Then I create a FunctionPass, inside the runOnFunction() I use the following codes to find direct and indirect function calls:</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"></p><p style="margin:0px"><span style="color:#931a68"><br></span></p><p style="margin:0px"><span style="color:#931a68">for</span> (Function::iterator b = F.begin(), be = F.end(); b != be; ++b) {</p>

<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">   </span><span style="color:#931a68">for</span> (BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; ++i) {</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">           </span><span style="color:#931a68">if</span> (CallInst* callInst = dyn_cast<CallInst>(&*i)) {</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                           </span> Function *fun = callInst->getCalledFunction();</p>
<p style="margin:0px;color:rgb(78,144,114)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre">                         </span> </span><span style="color:#931a68">if</span><span style="color:#000000">(fun){</span></p>

<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                   </span> errs().write_escaped(fun->getName());</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                           </span> }</p>
<p style="margin:0px;color:rgb(78,144,114)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre">                         </span> </span><span style="color:#931a68">else</span><span style="color:#000000">{</span></p>

<p style="margin:0px;color:rgb(57,51,255)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre">                                  </span> errs() <<</span>"indirect call: "<span style="color:#000000">;</span></p>

<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                   </span> Instruction* pinst = &*i;</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                   </span> <span style="color:#931a68">for</span>(User::op_iterator opi=pinst->op_begin(), opie=pinst->op_end(); opi!=opie; ++opi){</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                           </span> <span style="color:#931a68">if</span> (Instruction *Op = dyn_cast<Instruction>(*opi)){</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                                   </span> errs() <<Op->getOperand(0)->getName() <<<span style="color:#3933ff">", "</span>;</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                           </span> }<span style="color:#931a68">else</span>{</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                                   </span> errs() <<<span style="color:#3933ff">"</span><span style="text-decoration:underline;color:#3933ff">noti</span><span style="color:#3933ff">\n"</span>;</p>

<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                           </span> }</p>
<p style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                                   </span> }</p>
<p style="margin:0px;color:rgb(78,144,114)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre">                         </span> }</span></p>
<p style="margin:0px;color:rgb(78,144,114)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre">         </span> }</span><span class="Apple-tab-span" style="white-space:pre">     </span>  </p>
<p style="margin:0px;color:rgb(78,144,114)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"> </span>}</span></p><p style="margin:0px;color:rgb(78,144,114)"><span style="color:rgb(0,0,0)">}</span></p>
<p></p></div><div><br></div><div>The output is:</div><div><div>In function: main</div><div>A, </div><div>indirect call: tt1, </div><div>indirect call: ff2, </div><div>indirect call: tt4,</div><div>indirect call: ppp, </div>
<div>indirect call: kkk, </div></div><div><br></div><div><br></div><div>You can find that there is a number after tt and ff, I have no idea where they are coming from. Can anyone give some hint? </div><div><br></div><div>
Thanks.</div><div>Robert</div><div><br></div><div><br></div>