RFR: 8346914: UB issue in scalbnA

Kim Barrett kbarrett at openjdk.org
Fri Jun 20 16:10:39 UTC 2025


On Fri, 20 Jun 2025 16:06:24 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> Please review this change that replaces uses of our scalbnA function with
> using the standard scalbn function. Removed scalbnA, and also copysignA.
> 
> For more details, see first comment and JBS.
> 
> Testing: mach5 tier1-6. Though from discussion in
> https://github.com/openjdk/jdk/pull/25656, it's hard to get to our uses of
> scalbn/scalbnA.
> 
> Before removing it, I tested scalbnA via a gtest that is attached to the JBS
> issue.

Long ago we had our own scalbn and copysign, because we couldn't get those
functions from <math.h>. They are C99 functions. For gcc/clang we were using
C++98/03, which only includes C89 library functions. So gcc/clang <math.h>
version restricted them out. And MSVC++ <math.h> didn't have them at all.
Later, MSVC++ added them, without any version restriction since they didn't do
Standard versions back then. This collided with ours, so we renamed ours.
Later still we switched to C++14, which includes C99 library functions, so
they are no longer version restricted by gcc/clang.

scalbnA was recently being looked at because of possibile signed integer
overflow UB. And testing showed that was indeed the case. But testing also
showed that it was (as intended) pretty much compatible with scalbn. Since we
can now get scalbn from <math.h>, there's no reason to keep our own. We should
just use scalbn.

Our copysignA was similarly compatible with copysign, and was also only being
used by scalbnA. So there's no reason to keep it either.

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

PR Comment: https://git.openjdk.org/jdk/pull/25917#issuecomment-2992154785


More information about the hotspot-dev mailing list