[cfe-dev] Checking For The Overflow Of An Expr In A ASTMatcher

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 9 00:13:01 PST 2017


Hi,
I have two questions.
I wan to check for overflows in an ASTMatcher.
I only need to check for Exprs that are of type Int, so I figured I
could use Expr::EvaluateAsInt.
I have the following code:

#define START 0x80000000
#define END 0xFFFFFFFF
#define LEN 0x80000000

if ((START + LEN) > END)
{
   /*does something*/
}

Int size on my target(x86-64) is 32-bits so obviously START + LEN
should overflow.
when i call the APSInt.getExtValue() I get 4294967295 which has
overflowed and saturated. The type of the Expr is Int so the result is
saturated and then when i extend it with getExtValue its not going to
give me 4294967296 obviously.
My question is, is there a way to cast the result of the evaluation to
a wider type before it gets truncated?

I also thought i could use Expr::EvaluateForOverflow( const
ASTContext) but i cant figure out how it works.  My question is How
does it return a value I can check for?
The return type is void so i figured maybe its setting a flag
somewhere but I couldnt find it. I looked at Expr's attributes but no
luck. I thought maybe ASTContext holds the result but I couldn't find
anything there either.

-- 
Farzad Sadeghi
project mutator-https://github.com/bloodstalker/mutator



More information about the cfe-dev mailing list