Skip to content

Commit b4dc364

Browse files
committedMar 26, 2025
8346931: Replace divisions by zero in sharedRuntimeTrans.cpp
Reviewed-by: kbarrett, mdoerr
1 parent bc5cde1 commit b4dc364

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed
 

‎src/hotspot/share/runtime/sharedRuntimeTrans.cpp

+15-18
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
112112

113113
static double zero = 0.0;
114114

115-
ATTRIBUTE_NO_UBSAN
116115
static double __ieee754_log(double x) {
117116
double hfsq,f,s,z,R,w,t1,t2,dk;
118117
int k,hx,i,j;
@@ -126,8 +125,8 @@ static double __ieee754_log(double x) {
126125
k=0;
127126
if (hx < 0x00100000) { /* x < 2**-1022 */
128127
if (((hx&0x7fffffff)|lx)==0)
129-
return -two54/zero; /* log(+-0)=-inf */
130-
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
128+
return -std::numeric_limits<double>::infinity(); /* log(+-0)=-inf */
129+
if (hx<0) return std::numeric_limits<double>::quiet_NaN(); /* log(-#) = NaN */
131130
k -= 54; x *= two54; /* subnormal number, scale up x */
132131
hx = high(x); /* high word of x */
133132
}
@@ -209,7 +208,6 @@ ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
209208
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
210209
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
211210

212-
ATTRIBUTE_NO_UBSAN
213211
static double __ieee754_log10(double x) {
214212
double y,z;
215213
int i,k,hx;
@@ -223,8 +221,8 @@ static double __ieee754_log10(double x) {
223221
k=0;
224222
if (hx < 0x00100000) { /* x < 2**-1022 */
225223
if (((hx&0x7fffffff)|lx)==0)
226-
return -two54/zero; /* log(+-0)=-inf */
227-
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
224+
return -std::numeric_limits<double>::infinity(); /* log(+-0)=-inf */
225+
if (hx<0) return std::numeric_limits<double>::quiet_NaN(); /* log(-#) = NaN */
228226
k -= 54; x *= two54; /* subnormal number, scale up x */
229227
hx = high(x); /* high word of x */
230228
}
@@ -516,14 +514,16 @@ static double __ieee754_pow(double x, double y) {
516514
if(lx==0) {
517515
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
518516
z = ax; /*x is +-0,+-inf,+-1*/
519-
if(hy<0) z = one/z; /* z = (1/|x|) */
517+
if(hy<0) {
518+
if (ix == 0) {
519+
z = std::numeric_limits<double>::infinity();
520+
} else {
521+
z = one/z; /* z = (1/|x|) */
522+
}
523+
}
520524
if(hx<0) {
521525
if(((ix-0x3ff00000)|yisint)==0) {
522-
#ifdef CAN_USE_NAN_DEFINE
523-
z = NAN;
524-
#else
525-
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
526-
#endif
526+
z = std::numeric_limits<double>::quiet_NaN();
527527
} else if(yisint==1)
528528
z = -1.0*z; /* (x<0)**odd = -(|x|**odd) */
529529
}
@@ -534,12 +534,9 @@ static double __ieee754_pow(double x, double y) {
534534
n = (hx>>31)+1;
535535

536536
/* (x<0)**(non-int) is NaN */
537-
if((n|yisint)==0)
538-
#ifdef CAN_USE_NAN_DEFINE
539-
return NAN;
540-
#else
541-
return (x-x)/(x-x);
542-
#endif
537+
if((n|yisint)==0) {
538+
return std::numeric_limits<double>::quiet_NaN();
539+
}
543540

544541
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
545542
if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */

‎src/hotspot/share/utilities/globalDefinitions_gcc.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ inline int g_isnan(double f) { return isnan(f); }
8181
#error "missing platform-specific definition here"
8282
#endif
8383

84-
#define CAN_USE_NAN_DEFINE 1
85-
86-
8784
// Checking for finiteness
8885

8986
inline int g_isfinite(jfloat f) { return isfinite(f); }

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Mar 26, 2025

@openjdk-notifier[bot]
Please sign in to comment.