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(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

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(I->getCalledValue()->stripPointerCasts())) { … do whatever… } Regards, John Criswell

Thanks!! John. This has been extremely helpful.
Manish