"auto *IL = dyn_cast<IntegerLiteral>(e); " IL becomes NULL fails for negative integers.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

"auto *IL = dyn_cast<IntegerLiteral>(e); " IL becomes NULL fails for negative integers.

Kristof Beyls via cfe-dev


Hi All,


I need a support to find the below *IL  null pointer return for negative

integer numbers.

 

Checker code:


const Expr *e = vDecl->getInit();

auto *IL = dyn_cast<IntegerLiteral>(e);


if(IL !=NULL)

{

    double val = IL->getValue().signedRoundToDouble();

    cout << "val:" val;

}


test function:


main()

{

    int val = 100;  (int val = -100;)

    printf("%d", val);

}



if the local variable is positive ex: int var 100;  then cout prints the

right value "100".

But if the local variable is negative ex: int var -100;  then IL becomes

NULL and cout is not executed.


Please help me root cause this issue.


Thanks,

Devendran.




Sent from Yahoo Mail for iPad

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: "auto *IL = dyn_cast<IntegerLiteral>(e); " IL becomes NULL fails for negative integers.

Kristof Beyls via cfe-dev
The -100 is not the integer literal for 100 less than 0. It is the application of the unary operator '-' to the integer literal 100.

If you want to get the value, do the overload of isConstantExpr on Expr they takes a reference to APValue.

On Nov 2, 2019 1:16 PM, Devendran Mani via cfe-dev <[hidden email]> wrote:


Hi All,


I need a support to find the below *IL  null pointer return for negative

integer numbers.

 

Checker code:


const Expr *e = vDecl->getInit();

auto *IL = dyn_cast<IntegerLiteral>(e);


if(IL !=NULL)

{

    double val = IL->getValue().signedRoundToDouble();

    cout << "val:" val;

}


test function:


main()

{

    int val = 100;  (int val = -100;)

    printf("%d", val);

}



if the local variable is positive ex: int var 100;  then cout prints the

right value "100".

But if the local variable is negative ex: int var -100;  then IL becomes

NULL and cout is not executed.


Please help me root cause this issue.


Thanks,

Devendran.




Sent from Yahoo Mail for iPad

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev