RFR: 8324833: Signed integer overflows in ABS [v5]

Dean Long dlong at openjdk.org
Fri Feb 23 03:37:55 UTC 2024


On Thu, 22 Feb 2024 08:53:24 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> See the details in the bug. I think current `ABS` implementation is beyond repair, and we should just switch to `uabs`.
>> 
>> Additional testing:
>>  - [x] Linux x86_64 fastdebug, `all` with `-ftrapv` (now fully passes!)
>>  - [x] Linux x86_64 fastdebug, `all`
>
> Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix a place where we cast to jlong after uabs

src/hotspot/share/opto/loopnode.cpp line 812:

> 810: #endif
> 811:   // At least 2 iterations so counted loop construction doesn't fail
> 812:   if (iters_limit/uabs(stride_con) < 2) {

Previously negative values of iters_limit would cause us to return false here.  Now the comparison is unsigned, so we can get a different result:
stride_con is max_jint
iters_limit is -1
(unsigned) -1 / max_jint is 2
so we no longer return false here.
Using uabs with signed values is error-prone.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17617#discussion_r1500181710


More information about the graal-dev mailing list