[cfe-dev] [Clang Static Code Analyzer]: Need information about Callee.

Prashant Purohit Prashant.Purohit at kpit.com
Thu Dec 5 21:30:11 PST 2013


Hi all,

I need to know information about callee when a function is called using array of function pointer.

I have written following code to get the Callee name using Checker:
class SampleEvalCall : public Checker<eval::Call> {
public:
  bool evalCall(const CallExpr *CE, CheckerContext &C) const {
    /** Output function name */
   llvm::errs() << C.getCalleeName(CE) << " is called\n";
   return false;
  }
};

I am getting names for normal function calls but when a function is called using array function pointer, checker does not give any output.

Following is the sample program using function pointer where checker fails to give callee name.

///////////////////////////////////////////////////////////////////////////////////////////////////
#define ARRAY_SIZE1 2
#define ARRAY_SIZE2 2
#define IDX_00 0
#define TRUE 0
#define FALSE 1

typedef unsigned char U1;
typedef unsigned short U2;

typedef struct
{
    U2 mask;
    U1 a;
    U2 (*func_ptr)(void);
} STRUCT_1;

typedef struct
{
    U2 b;
    const STRUCT_1 * struct_ptr;
} STRUCT_2;

static U1 ram_var = 1;
static U1 index_2 = 0;

U2 func1(void)
{
    return((U2)ram_var);
}

U2 func2(void)
{
    ram_var = 3;
    return((U2)ram_var);
}

static const STRUCT_1 array1[ARRAY_SIZE1] =
{
    {
        (U2)TRUE,
        (U1)FALSE,
        &func1
    },
                {
        (U2)TRUE,
        (U1)FALSE,
        &func2
    }
};

static const STRUCT_2 array2[ARRAY_SIZE2] =
{
    {
        (U2)FALSE,
        &array1[IDX_00]
    }
};

int main()
{
    U2 index_1 = 1;
    U2 ret;
    /* I need to get list of function called by below function pointer. */
    ret = (*((array2[0].struct_ptr[0].func_ptr)))() &
              array2[index_2].struct_ptr[index_1].mask;

    return (int)ret;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

I understand that checker cannot get the callee name as it will be known at runtime but I need to get
the list of all functions that might be called in main function in above program. I need to get 'func1' and 'func2' function name in above
example from checker as a potential callee, one of which will definitely get called at run time.

Kindly suggest me a way to get this list.

Thanks,
Prashant S. Purohit
This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131206/fd1ed1d8/attachment.html>


More information about the cfe-dev mailing list