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

Aleksey Shipilev shade at openjdk.org
Thu Feb 22 08:59:54 UTC 2024


On Sat, 3 Feb 2024 19:14:40 GMT, Andrew Haley <aph at openjdk.org> wrote:

> I think it's confusing and error-prone to use uabs() for signed values. Using `checked_cast` silences warnings but doesn't handle the undefined behavior caused by values such as min_jint and min_jlong. 

Getting back to this...

AFAICS, `uabs` is well-defined: all possible values of `jlong` passed there, including `min_jlong` would be mapped to a correct unsigned value. We "only" need to make sure that the math is then done over unsigned values. I agree that immediately casting to `jlong` after `uabs` is dodgy when we can reasonably get the unsigned `julong` value from uabs that would not fit in `jlong`, making it negative. I think I fixed a single place where it can possibly happen.

I am re-running tests with -ftrapv now.

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

PR Comment: https://git.openjdk.org/jdk/pull/17617#issuecomment-1958982089


More information about the hotspot-dev mailing list