Skip to content

Commit 37cfaa8

Browse files
committedOct 23, 2024
8338449: ubsan: division by zero in sharedRuntimeTrans.cpp
Reviewed-by: lucy, kbarrett
1 parent a1ef818 commit 37cfaa8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

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

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "jni.h"
2727
#include "runtime/interfaceSupport.inline.hpp"
2828
#include "runtime/sharedRuntime.hpp"
29+
#include "sanitizers/ub.hpp"
30+
31+
#include <limits>
2932

3033
// This file contains copies of the fdlibm routines used by
3134
// StrictMath. It turns out that it is almost always required to use
@@ -110,11 +113,14 @@ ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
110113

111114
static double zero = 0.0;
112115

116+
ATTRIBUTE_NO_UBSAN
113117
static double __ieee754_log(double x) {
114118
double hfsq,f,s,z,R,w,t1,t2,dk;
115119
int k,hx,i,j;
116120
unsigned lx;
117121

122+
static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 required");
123+
118124
hx = high(x); /* high word of x */
119125
lx = low(x); /* low word of x */
120126

@@ -204,11 +210,14 @@ ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
204210
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
205211
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
206212

213+
ATTRIBUTE_NO_UBSAN
207214
static double __ieee754_log10(double x) {
208215
double y,z;
209216
int i,k,hx;
210217
unsigned lx;
211218

219+
static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 required");
220+
212221
hx = high(x); /* high word of x */
213222
lx = low(x); /* low word of x */
214223

@@ -440,13 +449,16 @@ bp[] = {1.0, 1.5,},
440449
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
441450
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
442451

452+
ATTRIBUTE_NO_UBSAN
443453
static double __ieee754_pow(double x, double y) {
444454
double z,ax,z_h,z_l,p_h,p_l;
445455
double y1,t1,t2,r,s,t,u,v,w;
446456
int i0,i1,i,j,k,yisint,n;
447457
int hx,hy,ix,iy;
448458
unsigned lx,ly;
449459

460+
static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 required");
461+
450462
i0 = ((*(int*)&one)>>29)^1; i1=1-i0;
451463
hx = high(x); lx = low(x);
452464
hy = high(y); ly = low(y);

0 commit comments

Comments
 (0)
Please sign in to comment.