[PATCH] D85778: More accurately compute the ranges of possible values for +, -, *, &, %.

Zequan Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 1 17:58:15 PDT 2020


zequanwu added a comment.

In D85778#2251173 <https://reviews.llvm.org/D85778#2251173>, @rsmith wrote:

> In D85778#2251160 <https://reviews.llvm.org/D85778#2251160>, @zequanwu wrote:
>
>> Hi, this change seems like hits a false positive case in chromium build: https://bugs.chromium.org/p/chromium/issues/detail?id=1124085
>
> That's not a false positive. The code is (simplified):
>
>   int RoundDown(int a, long b) { return a & -b; }
>
> ... which is implicitly converting an expression of type `long` to `int`, losing precision. For example, `RoundDown(-1, 0x1'0000'0000)` is -4294967296 prior to the implicit conversion from `long` to `int`. Given that the truncation is presumably intentional (0 at least seems like the least-bad answer for rounding down 0 to a multiple of 2^32 as a 32-bit integer), you can suppress the warning with a cast.

Sorry, I didn't notice that the type of second parameter is based on `__LP64__` (didn't scroll up...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85778



More information about the cfe-commits mailing list