RFR: 8361037: [ubsan] compiler/c2/irTests/TestFloat16ScalarOperations division by 0
Manuel Hässig
mhaessig at openjdk.org
Tue Jul 1 11:23:42 UTC 2025
On Tue, 1 Jul 2025 10:08:20 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:
> Floating point division by zero is undefined per the C and C++ standards, but is defined by Clang (and by ISO/IEC/IEEE 60559 / IEEE 754) as producing either an infinity or NaN value.
>
> While Java semantics defined in section 15.17.2 "Division Operator" of JLS-24 are well-defined for these constant-folding scenarios
>
> This bug fix patch fixes division by 0 error reported after integration of [JDK-8352635.](https://bugs.openjdk.org/browse/JDK-8352635)
> Kindly review and share your feedback.
>
> Best Regards,
> Jatin
Hi, @jatin-bhateja. Thank you for providing this fix.
I took a look at it and have a question. Otherwise, this looks good.
src/hotspot/share/opto/divnode.cpp line 833:
> 831: }
> 832:
> 833: if (g_isfinite(t1->getf()) && t2->getf() == 0.0) {
Is the `g_isfinite` for `t1` really needed? If the dividend is infinite then the result is also an infinity with the appropriate sign. Does this not result in `INF / 0.0` being calculated below? This would also be undefined by the C++ standard, would it not? Since as far as I know not all s390 models implement IEEE754, perhaps it would be better to remove the `g_isfinite` to prevent the native `INF / 0.0` below.
-------------
Changes requested by mhaessig (Committer).
PR Review: https://git.openjdk.org/jdk/pull/26062#pullrequestreview-2974972341
PR Review Comment: https://git.openjdk.org/jdk/pull/26062#discussion_r2177311121
More information about the hotspot-compiler-dev
mailing list