JDK-8361037 : [ubsan] compiler/c2/irTests/TestFloat16ScalarOperations division by 0
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: aarch64
  • Submitted: 2025-06-30
  • Updated: 2025-08-28
  • Resolved: 2025-07-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26 b05Fixed
Related Reports
Causes :  
Description
When running jtreg tests using ubsan-enabled binaries on Linux aarch64, the following issue is reported (test compiler/c2/irTests/TestFloat16ScalarOperations) :

/jdk/src/hotspot/share/opto/divnode.cpp:828:35: runtime error: division by zero
    #0 0xffffa7ffd458 in DivHFNode::Value(PhaseGVN*) const src/hotspot/share/opto/divnode.cpp:828
    #1 0xffffa9042a78 in PhaseIterGVN::transform_old(Node*) src/hotspot/share/opto/phaseX.cpp:2138
    #2 0xffffa9035d7c in PhaseIterGVN::optimize() src/hotspot/share/opto/phaseX.cpp:1054
    #3 0xffffa7dbbe20 in Compile::Optimize() src/hotspot/share/opto/compile.cpp:2414
    #4 0xffffa7dc6ce4 in Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*) src/hotspot/share/opto/compile.cpp:858
    #5 0xffffa7ae949c in C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*) src/hotspot/share/opto/c2compiler.cpp:141
    #6 0xffffa7ddb6d0 in CompileBroker::invoke_compiler_on_method(CompileTask*) src/hotspot/share/compiler/compileBroker.cpp:2323
    #7 0xffffa7dddc3c in CompileBroker::compiler_thread_loop() src/hotspot/share/compiler/compileBroker.cpp:1967
    #8 0xffffa8537d5c in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:773
    #9 0xffffa8537d5c in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:761
    #10 0xffffa96a8900 in Thread::call_run() src/hotspot/share/runtime/thread.cpp:243
    #11 0xffffa8f4bff4 in thread_native_entry src/hotspot/os/linux/os_linux.cpp:868
    #12 0xffffac6c2694 in start_thread (/lib64/libc.so.6+0x80694)
    #13 0xffffac72cbd8 in thread_start (/lib64/libc.so.6+0xeabd8)

Probably the issue is related to JDK-8352635 because this change removed a 0-check  ( t2->getf() != 0.0  ).
Comments
Changeset: 2f683fdc Branch: master Author: Jatin Bhateja <jbhateja@openjdk.org> Date: 2025-07-03 08:03:55 +0000 URL: https://git.openjdk.org/jdk/commit/2f683fdc4a8f9c227e878b0d7fca645fc8abe1b6
03-07-2025

ILW = Potential undefined behavior due to division by zero, with ubsan and single test, no workaround but disable compilation of affected method = MLH = P4
02-07-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/26062 Date: 2025-07-01 10:08:20 +0000
01-07-2025

[~mbaesken] Can you kindly verify https://github.com/openjdk/jdk/pull/26062 and approve if this fixes the reported issue.
01-07-2025

Thanks [~mbaesken] I am able to reproduce these cases. Through following c-reproducer. #include <stdio.h> #include <stdlib.h> #include <math.h> #define DEBUG(...) \ fprintf(stdout, __VA_ARGS__) int main() { DEBUG("NaN / NaN = %f\n", NAN / NAN); DEBUG("NaN / 2.0 = %f\n", NAN / 2.0f); DEBUG("2.0f / NaN = %f\n", 2.0f / NAN); DEBUG("INFINITY / INFINITY = %f\n", INFINITY / INFINITY); DEBUG("-INFINITY / INFINITY = %f\n", -INFINITY / INFINITY); DEBUG("INFINITY / -INFINITY = %f\n", INFINITY / -INFINITY); DEBUG("-INFINITY / -INFINITY = %f\n", INFINITY / INFINITY); DEBUG("INFINITY / 2.0 = %f\n", INFINITY / 2.0f); DEBUG("-INFINITY / 2.0 = %f\n", -INFINITY / 2.0f); DEBUG("INFINITY / -2.0 = %f\n", INFINITY / -2.0f); DEBUG("-INFINITY / -2.0 = %f\n", -INFINITY / -2.0f); DEBUG("2.0f / INFINITY = %f\n", 2.0f / INFINITY); DEBUG("2.0f / -INFINITY = %f\n", 2.0f / -INFINITY); DEBUG("-2.0f / INFINITY = %f\n", -2.0f / INFINITY); DEBUG("-2.0f / -INFINITY = %f\n", -2.0f / -INFINITY); DEBUG("0.0f / 0.0f= %f\n", 0.0f / 0.0f); DEBUG("0.0f / -2.0f= %f\n", 0.0f / -2.0f); DEBUG("0.0f / 2.0f= %f\n", 0.0f / 2.0f); DEBUG("-0.0f / 2.0f= %f\n", -0.0f / 2.0f); DEBUG("-0.0f / -2.0f= %f\n", -0.0f / -2.0f); DEBUG("2.0f / -0.0f= %f\n", 2.0f / -0.0f); DEBUG("-2.0f / 0.0f= %f\n", -2.0f / 0.0f); DEBUG("-2.0f / -0.0f= %f\n", -2.0f / -0.0f); DEBUG("2.0f / 0.0f= %f\n", 2.0f / 0.0f); return 0; } compiler command: gcc -fsanitize=float-divide-by-zero test.c 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 are well-defined for these constant-folding scenarios Results:- NaN / NaN = nan NaN / 2.0 = nan 2.0f / NaN = nan INFINITY / INFINITY = -nan -INFINITY / INFINITY = -nan INFINITY / -INFINITY = -nan -INFINITY / -INFINITY = -nan INFINITY / 2.0 = inf -INFINITY / 2.0 = -inf INFINITY / -2.0 = -inf -INFINITY / -2.0 = inf 2.0f / INFINITY = 0.000000 2.0f / -INFINITY = -0.000000 -2.0f / INFINITY = -0.000000 -2.0f / -INFINITY = 0.000000 test.c:29:3: runtime error: division by zero 0.0f / 0.0f= -nan 0.0f / -2.0f= -0.000000 0.0f / 2.0f= 0.000000 -0.0f / 2.0f= -0.000000 -0.0f / -2.0f= 0.000000 test.c:36:3: runtime error: division by zero 2.0f / -0.0f= -inf test.c:37:3: runtime error: division by zero -2.0f / 0.0f= -inf test.c:38:3: runtime error: division by zero -2.0f / -0.0f= inf test.c:39:3: runtime error: division by zero 2.0f / 0.0f= inf
01-07-2025

> Can you kindly verify https://github.com/openjdk/jdk/pull/26062 and approve if this fixes the reported issue. The test compiler/c2/irTests/TestFloat16ScalarOperations.java now passes on macOS aarch64 with ubsan enabled.
01-07-2025

[~jbhateja] could you please look into it? Maybe we still need the removed 0-check .
30-06-2025