Manish Gupta
2014-Jul-07 23:47 UTC
[LLVMdev] Return Type of Call Function with nested bitcast
Hi All, I am facing an issue with CallInst with nested bitcast instruction. I want to check if the return type of a call is void or non-void the below line works well for CallInst without bit cast. *cast<CallInst>(I)->getCalledFunction()->getReturnType()->isVoidTy()* But for Call instructions like *call void bitcast (void (%struct.jpeg_compress_struct.131*, i32)* @jinit_c_master_control to void (%struct.jpeg_compress_struct.109*, i32)*)(%struct.jpeg_compress_struct.109* %0, i32 0)* getCalledFuncion returns null and the pass crashes. Thanks! Manish -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140707/0b83ba57/attachment.html>
John Criswell
2014-Jul-08 00:59 UTC
[LLVMdev] Return Type of Call Function with nested bitcast
On 7/7/14, 6:47 PM, Manish Gupta wrote:> Hi All, > > I am facing an issue with CallInst with nested bitcast instruction. I > want to check if the return type of a call is void or non-void the > below line works well for CallInst without bit cast.First, there's a difference between the return type of the CallInst and the return type of the function being called (because you can cast function constants). If you want the value that will be used by users of the CallInst, simply look at the type of the CallInst. If you want the return type of the Function constant, you need to use getCalledValue()->stripPointerCasts() to get the Function constant (assuming that there is one; it could also be an indirect call with some non-const value as the function pointer). So, you'd do: if (Function * F = dyn_cast<Function>(I->getCalledValue()->stripPointerCasts())) { ... do whatever... } Regards, John Criswell> > *cast<CallInst>(I)->getCalledFunction()->getReturnType()->isVoidTy()* > > But for Call instructions like > *call void bitcast (void (%struct.jpeg_compress_struct.131*, i32)* > @jinit_c_master_control to void (%struct.jpeg_compress_struct.109*, > i32)*)(%struct.jpeg_compress_struct.109* %0, i32 0)* > * > * > getCalledFuncion returns null and the pass crashes. > > Thanks! > Manish > * > * > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140707/a8851439/attachment.html>
Manish Gupta
2014-Jul-09 00:04 UTC
[LLVMdev] Return Type of Call Function with nested bitcast
Thanks!! John. This has been extremely helpful. Manish On Mon, Jul 7, 2014 at 5:59 PM, John Criswell <jtcriswel at gmail.com> wrote:> On 7/7/14, 6:47 PM, Manish Gupta wrote: > > Hi All, > > I am facing an issue with CallInst with nested bitcast instruction. I > want to check if the return type of a call is void or non-void the below > line works well for CallInst without bit cast. > > > First, there's a difference between the return type of the CallInst and > the return type of the function being called (because you can cast function > constants). If you want the value that will be used by users of the > CallInst, simply look at the type of the CallInst. > > If you want the return type of the Function constant, you need to use > getCalledValue()->stripPointerCasts() to get the Function constant > (assuming that there is one; it could also be an indirect call with some > non-const value as the function pointer). So, you'd do: > > if (Function * F > dyn_cast<Function>(I->getCalledValue()->stripPointerCasts())) { > ... do whatever... > } > > Regards, > > John Criswell > > > *cast<CallInst>(I)->getCalledFunction()->getReturnType()->isVoidTy()* > > But for Call instructions like > *call void bitcast (void (%struct.jpeg_compress_struct.131*, i32)* > @jinit_c_master_control to void (%struct.jpeg_compress_struct.109*, > i32)*)(%struct.jpeg_compress_struct.109* %0, i32 0)* > > getCalledFuncion returns null and the pass crashes. > > Thanks! > Manish > > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140708/1f160a4c/attachment.html>