[PATCH] D113753: [Analyzer][Core] Better simplification in SimpleSValBuilder::evalBinOpNN

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 26 11:30:38 PST 2021


steakhal added a comment.

In D113753#3156270 <https://reviews.llvm.org/D113753#3156270>, @bjope wrote:

> This seem to cause some weird results.
>
> Given this input:
>
>   bar(short k) {
>     k++;
>     for (short f = 0; f < k; f++)
>       ;
>     (long)k << 16;
>   }
>
> we get
>
>   > clang  --analyze --target=x86_64 'bbi-63538.c'
>   bbi-63538.c:5:11: warning: The result of the left shift is undefined due to shifting '1' by '16', which is unrepresentable in the unsigned version of the return type 'long' [core.UndefinedBinaryOperatorResult]
>     (long)k << 16;
>     ~~~~~~~ ^
>   bbi-63538.c:5:11: warning: The result of the left shift is undefined due to shifting '2' by '16', which is unrepresentable in the unsigned version of the return type 'long' [core.UndefinedBinaryOperatorResult]
>     (long)k << 16;
>     ~~~~~~~ ^
>   bbi-63538.c:5:11: warning: The result of the left shift is undefined due to shifting '3' by '16', which is unrepresentable in the unsigned version of the return type 'long' [core.UndefinedBinaryOperatorResult]
>     (long)k << 16;
>     ~~~~~~~ ^
>   3 warnings generated.

Good catch @bjope !
Here is an example without the loop: https://godbolt.org/z/z3rqMz4bs
We'll have a closer look.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113753/new/

https://reviews.llvm.org/D113753



More information about the cfe-commits mailing list