[PATCH] D13126: New static analyzer checker for loss of sign/precision

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 10:02:04 PST 2015

NoQ added a subscriber: NoQ.
NoQ added a comment.

In http://reviews.llvm.org/D13126#291763, @danielmarjamaki wrote:

> I have problems with the "default" handling of expressions.
> I want to warn about loss of precision for such code:
>   unsigned int x = 256;
>   unsigned char c;
>   c = x;
> The analyser tells me that the RHS value is 0 instead of 256 in the assignment "c = x". Here is the dump of the ProgramState:
> Store (direct and default bindings), 0x0 :
> Expressions:
>  (0x7b9bd30,0x7b458d8) c : &c
>  (0x7b9bd30,0x7b45940) x : 0 U8b
>  Ranges are empty.

Hmm. I guess you need to sign up for the cast expression rather than for the binary operator expression. By the time you reach the assignment operator, the value before the cast is already removed from the environment.


More information about the cfe-commits mailing list