[cfe-dev] How to get the type clang::Expr evaluates to?

Alexander Droste via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 26 14:33:43 PDT 2015


Thanks for your reply!

clang::Expr::getType() seems to return
the arg type it is casted to (if possible)
when passed to function and not the original arg type.

If I have a function like func(int)
and I pass a float func(1.1)
callExpr()->getArg(1)->getType()->dump()
gives me: BuiltinType 0x7f833183b1b0 'int'

-Alex

On 26.08.15 22:58, Aaron Ballman wrote:
> On Wed, Aug 26, 2015 at 4:56 PM, Alexander Droste via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> Hi everyone,
>>
>> is it possible to get the type of a clang::Expr instance
>> the expression evaluates to?
>
> You should be able to use clang::Expr::getType().
>
> ~Aaron
>
>> I would like to use this, to find out
>> what kind of types arguments passed to a clang::CallExpr have.
>>
>> Sth. like this:
>>
>> int n;
>> function(&n);
>> ..
>> // getArg() returns Expr
>> callExpr()->getArg(idx)--->getTypeExprEvaluatesTo(); // -> *int
>>
>> or with multiple operands:
>> int n;
>> function(1 + n);
>> ..
>> callExpr()->getArg(idx)--->getTypeExprEvaluatesTo(); // -> int
>>
>> -Alex
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list