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

Andrew Haley aph at openjdk.org
Sat Feb 3 19:17:02 UTC 2024


On Sat, 3 Feb 2024 00:04:27 GMT, Dean Long <dlong 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.

uabs itself has no UB. I don't think checked_cast has either: at worst it's implementation defined.

> I suggest fixing ABS so that it first calls uabs and then safely converts to signed, checking for negative values caused by MIN INT inputs.

That's a good idea too, but it doesn't solve the problems uabs was designed to solve.

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

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


More information about the graal-dev mailing list