[cfe-dev] Getting the value of a IntegerLiteral

Jesper Eskilson jesper.eskilson at iar.com
Fri Sep 13 03:07:13 PDT 2013


On 09/13/2013 12:02 PM, Jesper Eskilson wrote:
> On 09/12/2013 04:51 PM, David Blaikie wrote:
>> Are you using a +asserts build? What kind of crash are you observing?
>>
> wtd-analyzer:
> /home/jesperes/dev/clang-install/include/llvm/ADT/APInt.h:1316: int64_t
> llvm::APInt::getSExtValue() const: Assertion `getMinSignedBits() <= 64
> && "Too many bits for int64_t"' failed.
>        [exec] Stack dump:
>        [exec] 0.    <eof> parser at end of file
>
> Not sure what that means.

I discovered that I really don't need the integer literal as an integer, 
since it will be converted to a string anyway, so I went with

getValue().toString(10, true);

instead.

> On Sep 12, 2013 6:42 AM, "Jesper Eskilson" <jesper.eskilson at iar.com
> <mailto:jesper.eskilson at iar.com>> wrote:
>>
>>      Hi,
>>
>>      I'm trying to figure out how I can obtain the value of an
>>      IntegerLiteral. I tried the following:
>>
>>      const IntegerLiteral *lit = ...;
>>      if (lit != 0)
>>      {
>>          int64_t n = lit->getValue().getSExtValue();
>>          // do something with n
>>      }
>>
>>      This seems to work sometimes, but frequently crashes. I've tried
>>      to figure out how to use the Evaluate*-functions in the Expr
>>      class, but I cannot figure out how they should be called.
>>
>>      It's ok if obtaining the value sometimes fails, but it would be
>>      nice if it didn't crash. :)
>>
>>      --
>>      *Jesper Eskilson* /Development Engineer/
>>      IAR Systems AB
>>      Box 23051, Strandbodgatan 1
>>      SE-750 23 Uppsala, SWEDEN
>>      E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
>>      <mailto:jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>>
>>      Website: www.iar.com <http://www.iar.com>
>>      <http://www.iar.com> Twitter: www.twitter.com/iarsystems
>>      <http://www.twitter.com/iarsystems>
>>      <http://www.twitter.com/iarsystems>
>>      _______________________________________________
>>      cfe-dev mailing list
>>      cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
>>      http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>


-- 
*Jesper Eskilson* /Development Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com> 
Website: www.iar.com
<http://www.iar.com> Twitter: www.twitter.com/iarsystems 
<http://www.twitter.com/iarsystems>



More information about the cfe-dev mailing list