[cfe-dev] How to get argument names from clang::CallExpr?

Kenth Eriksson via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 24 00:29:06 PDT 2019


> What if you don't try to cast it to a `DeclRefExpr`, but you cast it
> to 
> a `Expr` and `->dump()` it?
> 

If I dump the CallExpr, I can see the following;

CallExpr 0x5640de2c08c8 'char *'
|-ImplicitCastExpr 0x5640de2c08b0 'char *(*)(char *, const char *)' <FunctionToPointerDecay>
| `-DeclRefExpr 0x5640de2c07f0 'char *(char *, const char *)' Function 0x5640de2916a8 'strcpy' 'char *(char *, const char *)'
|-ImplicitCastExpr 0x5640de2c08f8 'char *' <LValueToRValue>
| `-UnaryOperator 0x5640de2c0848 'char *' lvalue prefix '*' cannot overflow
|   `-ImplicitCastExpr 0x5640de2c0830 'char **' <LValueToRValue>
|     `-DeclRefExpr 0x5640de2c0810 'char **' lvalue ParmVar 0x5640de366998 'valueString' 'char **'
`-ImplicitCastExpr 0x5640de2c0928 'const char *' <NoOp>
  `-ImplicitCastExpr 0x5640de2c0910 'char *' <LValueToRValue>
    `-DeclRefExpr 0x5640de2c0860 'char *' lvalue Var 0x5640de366d88 'ptr1' 'char *'

I want to get the name of the first argument supplied to the call of
strcpy.

Note that some args are not represented by `DeclRefExpr` if they are 
> literals such as IntegerLiteral or StringLiteral.
>  





More information about the cfe-dev mailing list