Setting called value for an indirect function call


I am trying to clone some call instructions in the IR and then set the
call destination of those call instructions to my own library
functions that happens to have the same arguments and return types of
the original callee.

It works perfectly for direct calls using setCalledFunction(). But
when the function call is indirect, is there a way to set the callee?
Something like setCalledValue()? How do I achieve this?

Any help will be appreciated, thanks a lot!

Try the setCalledFunction() method of CallInst. Despite the name, it looks like it takes a generic Value *, which means it should be able to set the called function operand to either a Function * or to a computed, indirect value (e.g., a Value *).

-- John T.