6ca6e8
commit 80b24b86548eee3d96130a48e760d1d6c2e0c587
6ca6e8
Author: H.J. Lu <hjl.tools@gmail.com>
6ca6e8
Date:   Mon Dec 20 15:00:24 2021 -0800
6ca6e8
6ca6e8
    math: Properly cast X_TLOSS to float [BZ #28713]
6ca6e8
    
6ca6e8
    Add
6ca6e8
    
6ca6e8
     #define AS_FLOAT_CONSTANT_1(x) x##f
6ca6e8
     #define AS_FLOAT_CONSTANT(x) AS_FLOAT_CONSTANT_1(x)
6ca6e8
    
6ca6e8
    to cast X_TLOSS to float at compile-time to fix:
6ca6e8
    
6ca6e8
    FAIL: math/test-float-j0
6ca6e8
    FAIL: math/test-float-jn
6ca6e8
    FAIL: math/test-float-y0
6ca6e8
    FAIL: math/test-float-y1
6ca6e8
    FAIL: math/test-float-yn
6ca6e8
    FAIL: math/test-float32-j0
6ca6e8
    FAIL: math/test-float32-jn
6ca6e8
    FAIL: math/test-float32-y0
6ca6e8
    FAIL: math/test-float32-y1
6ca6e8
    FAIL: math/test-float32-yn
6ca6e8
    
6ca6e8
    when compiling with GCC 12.
6ca6e8
    
6ca6e8
    Reviewed-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>
6ca6e8
    (cherry picked from commit 6e30181b4a3ab6c56da0378b65f4d60504982300)
6ca6e8
6ca6e8
diff --git a/math/math-svid-compat.h b/math/math-svid-compat.h
6ca6e8
index 5c18cb1b039cb3be..876cadde4084dab0 100644
6ca6e8
--- a/math/math-svid-compat.h
6ca6e8
+++ b/math/math-svid-compat.h
6ca6e8
@@ -49,6 +49,8 @@ extern int matherr (struct exception *__exc);
6ca6e8
 extern int __matherr (struct exception *__exc);
6ca6e8
 
6ca6e8
 #define X_TLOSS	1.41484755040568800000e+16
6ca6e8
+#define AS_FLOAT_CONSTANT_1(x) x##f
6ca6e8
+#define AS_FLOAT_CONSTANT(x) AS_FLOAT_CONSTANT_1(x)
6ca6e8
 
6ca6e8
 /* Types of exceptions in the `type' field.  */
6ca6e8
 #define DOMAIN		1
6ca6e8
diff --git a/math/w_j0f_compat.c b/math/w_j0f_compat.c
6ca6e8
index a4882eadb33853b2..f35a55219f7baa78 100644
6ca6e8
--- a/math/w_j0f_compat.c
6ca6e8
+++ b/math/w_j0f_compat.c
6ca6e8
@@ -28,7 +28,8 @@
6ca6e8
 float
6ca6e8
 __j0f (float x)
6ca6e8
 {
6ca6e8
-  if (__builtin_expect (isgreater (fabsf (x), (float) X_TLOSS), 0)
6ca6e8
+  if (__builtin_expect (isgreater (fabsf (x),
6ca6e8
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
6ca6e8
     /* j0(|x|>X_TLOSS) */
6ca6e8
     return __kernel_standard_f (x, x, 134);
6ca6e8
@@ -43,7 +44,7 @@ float
6ca6e8
 __y0f (float x)
6ca6e8
 {
6ca6e8
   if (__builtin_expect (islessequal (x, 0.0f)
6ca6e8
-                        || isgreater (x, (float) X_TLOSS), 0)
6ca6e8
+                        || isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_)
6ca6e8
     {
6ca6e8
       if (x < 0.0f)
6ca6e8
diff --git a/math/w_j1f_compat.c b/math/w_j1f_compat.c
6ca6e8
index f2ec7b327d2bc90a..c5e3ccd035031799 100644
6ca6e8
--- a/math/w_j1f_compat.c
6ca6e8
+++ b/math/w_j1f_compat.c
6ca6e8
@@ -28,7 +28,8 @@
6ca6e8
 float
6ca6e8
 __j1f (float x)
6ca6e8
 {
6ca6e8
-  if (__builtin_expect (isgreater (fabsf (x), X_TLOSS), 0)
6ca6e8
+  if (__builtin_expect (isgreater (fabsf (x),
6ca6e8
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
6ca6e8
     /* j1(|x|>X_TLOSS) */
6ca6e8
     return __kernel_standard_f (x, x, 136);
6ca6e8
@@ -43,7 +44,7 @@ float
6ca6e8
 __y1f (float x)
6ca6e8
 {
6ca6e8
   if (__builtin_expect (islessequal (x, 0.0f)
6ca6e8
-			|| isgreater (x, (float) X_TLOSS), 0)
6ca6e8
+			|| isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_)
6ca6e8
     {
6ca6e8
       if (x < 0.0f)
6ca6e8
diff --git a/math/w_jnf_compat.c b/math/w_jnf_compat.c
6ca6e8
index fb6e5060096fb070..925ccc4cd0988a8f 100644
6ca6e8
--- a/math/w_jnf_compat.c
6ca6e8
+++ b/math/w_jnf_compat.c
6ca6e8
@@ -28,7 +28,8 @@
6ca6e8
 float
6ca6e8
 __jnf (int n, float x)
6ca6e8
 {
6ca6e8
-  if (__builtin_expect (isgreater (fabsf (x), (float) X_TLOSS), 0)
6ca6e8
+  if (__builtin_expect (isgreater (fabsf (x),
6ca6e8
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
6ca6e8
     /* jn(n,|x|>X_TLOSS) */
6ca6e8
     return __kernel_standard_f (n, x, 138);
6ca6e8
@@ -43,7 +44,7 @@ float
6ca6e8
 __ynf (int n, float x)
6ca6e8
 {
6ca6e8
   if (__builtin_expect (islessequal (x, 0.0f)
6ca6e8
-			|| isgreater (x, (float) X_TLOSS), 0)
6ca6e8
+			|| isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
6ca6e8
       && _LIB_VERSION != _IEEE_)
6ca6e8
     {
6ca6e8
       if (x < 0.0f)