Need help in understanding CallSite

Hi All,

I have a custom Pass which will identify a few functions in the .cpp
code and process them.
It was working fine for almost all the functions except for a function
which has class objects as its arguments.

Details:
For a particular function the CallSite CS(*iUse); CS is zero. When I
debugged the code the CallSite was expecting the *iUse to be InstTy
but this particular function is having the type UnaryConstantExpr. Due
to this the CS is zero.

I want to understand why this specific function has the UnaryConstantExpr type?
Any reference to documents or links will be a great help.

CallSite.h:
static CallSiteBase get(ValTy *V) {
    if (InstrTy *II = dyn_cast<InstrTy>(V)) {

CustomPass:
//aFuncs has the custom functions list from .cpp
for(AFuncList::iterator iFunc=aFuncs.begin(); iFunc!=aFuncs.end(); iFunc++){
      Function *f = *iFunc;
      for(Value::user_iterator iUse = f->user_begin(); iUse !=
f->user_end(); iUse++){
        CallSite CS(*iUse);
        if ( CS ){
          BasicBlock *bb = CS.getInstruction()->getParent();

CallSite and CallSiteBase were removed in fdbf493a705c. I’m assuming you’re working on a branch before that. To future-proof the code, it’d be probably best to not use CallSite, and instead use CallBase (an Instruction, base class to CallInst, CallBrInst or InvokeInst) and get the information from it, e.g. getCalledOperand.

For your case, could it be that the use of the function is not a call, but, for example, an expression taking the address of the function? When debugging, I find it useful to call dump() on the various objects of interest, it very quickly reveals what’s happening.

Hi Mircea,

Thanks for the reply.

CallSite and CallSiteBase were removed in fdbf493a705c. I'm assuming you're working on a branch before that. To future-proof the code, it'd be probably best to not use CallSite, and instead use CallBase (an Instruction, base class to CallInst, CallBrInst or InvokeInst) and get the information from it, e.g. getCalledOperand.

Sorry I forgot to mention the version. I am using the LLVM 3.9 and
have some tool dependencies with the version so had to stay on this
older release.

For your case, could it be that the use of the function is not a call, but, for example, an expression taking the address of the function? When debugging, I find it useful to call dump() on the various objects of interest, it very quickly reveals what's happening.

This is definitely a function call, after using the dump() and
analyzing the IR I found that <bitcast> is being used. Due to
<bitcast> the f->user_begin() is not getting the proper InstTy.

Thanks,
Nagaraju