RFR: 8338449: ubsan: division by zero in sharedRuntimeTrans.cpp
Matthias Baesken
mbaesken at openjdk.org
Wed Oct 16 07:25:15 UTC 2024
On Tue, 15 Oct 2024 19:46:09 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> src/hotspot/share/runtime/sharedRuntimeTrans.cpp line 122:
>>
>>> 120: unsigned lx;
>>> 121:
>>> 122: static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 required");
>>
>> I'm not sure what the implications of this actually are. Do we really need it? Maybe @jddarcy can comment?
>
>> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21500#discussion_r1802501457
More information about the hotspot-dev
mailing list