<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 3/10/13 11:17 PM, Jane wrote:<br>
    </div>
    <blockquote cite="mid:tencent_5C709E857ED638287393BDAB@qq.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <div><br>
      </div>
      <div>Hi,</div>
      <div>    I'm trying to write a pass to detect all free()/delete()
        call instructions in LLVM IR.<span style="line-height: 1.5;">The
          method is as follows.</span></div>
      <div>    First I find Call Instructions: <u>CallInst
          *CI=dyn_cast<CallInst>(&*i);</u></div>
      <div>    then see if the Function name matches:</div>
      <div>                        <u>name=CI->getCalledFunction()->getName();
          if(name=="_ZdlPv"||name=="_ZdaPv"||name=="free")</u></div>
      <div>    It worked but when <span style="line-height: 1.5;"> </span><span
          style="line-height: 1.5;">something like this occurs</span></div>
      <div>   <u> %call2 = call i32 bitcast (i32 (...)* @free to i32
          (i8*)*)(i8* %call1) nounwind, !dbg !16</u></div>
      <div>    It seems like a indirect function call and I don't know
        how to detect free() in such situation.</div>
      <div>    By the way, is there any way that is more convenient to <span
          style="line-height: 1.5;">detect all free()/delete() call
          instructions in a module except by matching the function name?</span></div>
    </blockquote>
    <br>
    As others have mentioned, to handle situations in which the function
    pointer is casted before the call, fetch the called SSA value using
    Function::getCalledValue() and then use the stripPointerCasts()
    method to remove all the casts.<br>
    <br>
    However, that only solves the problem of calls to free() that cast
    the free() function pointer.  It is also possible that an indirect
    function call calls free() as well.  To find those, you'll need to
    use the CallGraph interface or, better yet, the DSCallGraph
    interface from DSA (which is located in the poolalloc project).<br>
    <br>
    -- John T.<br>
    <br>
    <blockquote cite="mid:tencent_5C709E857ED638287393BDAB@qq.com"
      type="cite"><br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>