[cfe-dev] "*IL = dyn_cast<IntegerLiteral>(e); " fails for negative integers

Michael Kruse via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 4 08:28:11 PST 2019


As explained in [1], there are no negative integer literals. What you
should match for is an UnaryOperator of a (postive) IntegerLiteral

Michael

[1] https://en.cppreference.com/w/cpp/language/integer_literal

Am So., 3. Nov. 2019 um 14:51 Uhr schrieb Devendran Mani via cfe-dev
<cfe-dev at lists.llvm.org>:
>
> Hi All,
>
> I need a support to find the below *IL  null pointer return for negative
> integer numbers.
>
> 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 the cout is skipped.
>
> Please help me root cause this issue.
>
> Thanks,
> Devendran.
>
>
>
> --
> Sent from: http://clang-developers.42468.n3.nabble.com/
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list