[cfe-dev] CGCalleeInfo set Decl to Null while using as dereferenced callee

Mustakimur Rahman Khandaker (Mustakim) via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 17 08:59:27 PDT 2018


If I have the FieldDecl from a MemberExpression, is there anyway to extract the VarDecl of that FieldDecl for that MemberExpr? Or is there no VarDecl in such case? I basically want to extract the Address of that FieldDecl as like I can for VarDecl using GetAddrOfLocalVar.

Basically, this is the AST:
CStyleCastExpr 0x55d2681bcf68 'MathFuncNoArg':'double (*)(void)' <BitCast>
`-ImplicitCastExpr 0x55d2681bcf50 'MathFunc':'double (*)(...)' <LValueToRValue>
`-MemberExpr 0x55d2681bcf08 'MathFunc':'double (*)(...)' lvalue .f 0x55d26800bec0
`-MemberExpr 0x55d2681bced0 'struct (anonymous struct at omnet_include/cpar.h:277:8)':'struct cPar::(anonymous at omnet_include/cpar.h:277:8)' lvalue .func 0x55d26800c188
`-MemberExpr 0x55d2681bce80 'union cPar::(anonymous at omnet_include/cpar.h:272:5)' lvalue -> 0x55d268013d58
`-CXXThisExpr 0x55d2681bce68 'class cPar *' this

and in the source:
((MathFuncNoArg)func.f)()
On Sep 14 2018, at 8:54 am, Mustakimur Rahman Khandaker (Mustakim) <mustakcsecuet at gmail.com> wrote:
>
> I actually try to instrument before those indirect call to extract the memory address of callee (in above case: func.f). I know I can extract that using GetAddrOfLocalVar if I know the Decl of the callee. But, the point I reached to createCall for indirect call, I don't have that information anymore for these cases. I don't know if there could be an alternative design possible to achieve it.
> On Sep 13 2018, at 6:29 pm, Friedman, Eli <efriedma at codeaurora.org> wrote:
> >
> >
> > On 9/13/2018 2:26 PM, Mustakimur Rahman Khandaker (Mustakim) via cfe-dev wrote:
> > > Now, in the CGCalleeInfo, compiler set the Decl for the Callee. What I have discovered is that Decl *Expr::getReferencedDeclOfCallee() returns nullptr and for that call callee set to Decl as Null from CGCallee CodeGenFunction::EmitCallee(const Expr *E). I beleive this is not an expected behavior because it is declared as MathFunc and it should be set as that.
> > >
> > > I would like to understand why it kept like this?
> > It mostly doesn't matter because the callers of getReferencedDeclOfCallee/getCalleeDecl generally don't care about declarations that aren't a FunctionDecl, and code generally doesn't call explicit casts of function pointers.
> > What are you trying to do?
> > -Eli
> >
> > --
> >
> > Employee of Qualcomm Innovation Center, Inc.
> > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
> >
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180917/0d185f49/attachment.html>


More information about the cfe-dev mailing list