RFR: 8338449: ubsan: division by zero in sharedRuntimeTrans.cpp
Lutz Schmidt
lucy at openjdk.org
Mon Oct 21 08:14:11 UTC 2024
On Wed, 16 Oct 2024 07:22:38 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:
>>> I'm not sure what the implications of this actually are. Do we really need it? Maybe @jddarcy can comment?
>>
>> It needs to return -Inf. ubsan seems wrong here: this IEEE-754 arithmetic is well defined, and has been for a very long while.
>
> Ubsan is just following the C++ standard
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
> 5.6 Multiplicative operators
> ....
> 'The binary / operator yields the quotient, and the binary % operator yields the remainder from the division
> of the first expression by the second. If the second operand of / or % is zero the behavior is undefined.'
>
> See also https://stackoverflow.com/questions/42926763/the-behaviour-of-floating-point-division-by-zero .
>
> However on our set of platforms in OpenJDK we probably get away with the expected results when dividing by 0 (because they all seem to follow IEEE-754).
> That's why I just added the static_assert.
To me, this feels like the C++ standard is not compatible with IEEE-754 arithmetic. Undefined behavior would give the optimizer freedom to do whatever it likes to do. That is in contrast to the well-defined IEEE-754 requirement.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21500#discussion_r1808300823
More information about the hotspot-dev
mailing list