Hi Jane,<br><br>On your bitcast case: you can easily strip them using:<br><br>Function* callee = dyn_cast<Function>(call->getCalledValue()->stripPointerCasts());<br><br>- D.<br><br><div class="gmail_quote">2013/3/11 Xi Wang <span dir="ltr"><<a href="mailto:xi.wang@gmail.com" target="_blank">xi.wang@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">if you don't include stdlib.h, where free() is declared, you'll simply<br>
get a default C function signature:<br>
<br>
int free(...);<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, Mar 11, 2013 at 1:56 AM, Jane <<a href="mailto:270611649@qq.com">270611649@qq.com</a>> wrote:<br>
> Thanks. isFreeCall() works well but for<br>
> %call2 = call i32 bitcast (i32 (...)* @free to i32 (i8*)*)(i8* %call1)<br>
> nounwind, !dbg !16<br>
> So I tried to figure out when the above instruction occurred.<br>
> When <stdlib.h> is included, free(buf2R1); turn into call void @free(i8*<br>
> %call1) nounwind, !dbg !16<br>
> when I forget to include <stdlib.h>, free(buf2R1); turn into %call2 = call<br>
> i32 bitcast (i32 (...)* @free to i32 (i8*)*)(i8* %call1) nounwind, !dbg !16<br>
> I don't understand why this is happen. Could you explain it for me?<br>
><br>
> ------------------ Original ------------------<br>
> From: "Xi Wang"<<a href="mailto:xi.wang@gmail.com">xi.wang@gmail.com</a>>;<br>
> Date: Mon, Mar 11, 2013 12:24 PM<br>
> To: "Jane"<<a href="mailto:270611649@qq.com">270611649@qq.com</a>>;<br>
> Cc: "llvmdev"<<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>>;<br>
> Subject: Re: [LLVMdev] How to detect all free() calls<br>
><br>
> Try isFreeCall() defined in "llvm/Analysis/MemoryBuiltins.h".<br>
><br>
> On Mon, Mar 11, 2013 at 12:17 AM, Jane <<a href="mailto:270611649@qq.com">270611649@qq.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>> I'm trying to write a pass to detect all free()/delete() call<br>
>> instructions in LLVM IR.The method is as follows.<br>
>> First I find Call Instructions: CallInst *CI=dyn_cast<CallInst>(&*i);<br>
>> then see if the Function name matches:<br>
>> name=CI->getCalledFunction()->getName();<br>
>> if(name=="_ZdlPv"||name=="_ZdaPv"||name=="free")<br>
>> It worked but when something like this occurs<br>
>> %call2 = call i32 bitcast (i32 (...)* @free to i32 (i8*)*)(i8* %call1)<br>
>> nounwind, !dbg !16<br>
>> It seems like a indirect function call and I don't know how to detect<br>
>> free() in such situation.<br>
>> By the way, is there any way that is more convenient to detect all<br>
>> free()/delete() call instructions in a module except by matching the<br>
>> function name?<br>
>><br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br>