diff mbox series

Workaround glibc <= 2.23 nextafterl/nexttowardl bug (PR tree-optimization/85699)

Message ID 20180509205205.GZ8577@tucnak
State New
Headers show
Series Workaround glibc <= 2.23 nextafterl/nexttowardl bug (PR tree-optimization/85699) | expand

Commit Message

Jakub Jelinek May 9, 2018, 8:52 p.m. UTC
Hi!

glibc <= 2.23 has buggy nextafterl/nexttowardl as can be seen on the
nextafter-2.c testcase.

Do we want to workaround this bug, e.g. with the following patch?

Regtested on x86_64-linux (with glibc 2.26).  Ok for trunk?

2018-05-09  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/85699
	* gcc.dg/nextafter-1.c (NO_LONG_DOUBLE): Define if not defined.  Use
	!NO_LONG_DOUBLE instead of __LDBL_MANT_DIG__ != 106.
	* gcc.dg/nextafter-2.c: Include stdlib.h.  For glibc < 2.24 define
	NO_LONG_DOUBLE to 1 before including nextafter-1.c.


	Jakub

Comments

Richard Biener May 10, 2018, 5:53 a.m. UTC | #1
On May 9, 2018 10:52:05 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>glibc <= 2.23 has buggy nextafterl/nexttowardl as can be seen on the
>nextafter-2.c testcase.
>
>Do we want to workaround this bug, e.g. with the following patch?

Works for me. Was the reason to test the target libc to test the compare against arithmetic? 

Thanks, 
Richard. 

>Regtested on x86_64-linux (with glibc 2.26).  Ok for trunk?
>
>2018-05-09  Jakub Jelinek  <jakub@redhat.com>
>
>	PR tree-optimization/85699
>	* gcc.dg/nextafter-1.c (NO_LONG_DOUBLE): Define if not defined.  Use
>	!NO_LONG_DOUBLE instead of __LDBL_MANT_DIG__ != 106.
>	* gcc.dg/nextafter-2.c: Include stdlib.h.  For glibc < 2.24 define
>	NO_LONG_DOUBLE to 1 before including nextafter-1.c.
>
>--- gcc/testsuite/gcc.dg/nextafter-1.c.jj	2018-05-06 23:12:48.952619545
>+0200
>+++ gcc/testsuite/gcc.dg/nextafter-1.c	2018-05-09 14:58:53.694198614
>+0200
>@@ -20,6 +20,9 @@ long double nexttowardl (long double, lo
> #ifndef NEED_EXC
> #define NEED_EXC 0
> #endif
>+#ifndef NO_LONG_DOUBLE
>+#define NO_LONG_DOUBLE (__LDBL_MANT_DIG__ == 106)
>+#endif
> 
> #define TEST(name, fn, type, L1, L2, l1, l2, MIN1,			     \
> 	     MAX1, DENORM_MIN1, EPSILON1, MIN2, MAX2, DENORM_MIN2)	     \
>@@ -129,7 +132,7 @@ TEST (test1, nextafterf, float, F, F, f,
> TEST (test2, nextafter, double, , , , , __DBL_MIN__, __DBL_MAX__,
>       __DBL_DENORM_MIN__, __DBL_EPSILON__, __DBL_MIN__, __DBL_MAX__,
>       __DBL_DENORM_MIN__)
>-#if __LDBL_MANT_DIG__ != 106
>+#if !NO_LONG_DOUBLE
>TEST (test3, nextafterl, long double, L, L, l, l, __LDBL_MIN__,
>__LDBL_MAX__,
>     __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
>       __LDBL_DENORM_MIN__)
>@@ -149,7 +152,7 @@ main ()
> {
>   test1 ();
>   test2 ();
>-#if __LDBL_MANT_DIG__ != 106
>+#if !NO_LONG_DOUBLE
>   test3 ();
>   test4 ();
>   test5 ();
>--- gcc/testsuite/gcc.dg/nextafter-2.c.jj	2018-05-08 13:56:38.265930160
>+0200
>+++ gcc/testsuite/gcc.dg/nextafter-2.c	2018-05-09 14:59:45.527245803
>+0200
>@@ -5,4 +5,13 @@
> /* { dg-add-options ieee } */
> /* { dg-add-options c99_runtime } */
> 
>+#include <stdlib.h>
>+
>+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
>+# if !__GLIBC_PREREQ (2, 24)
>+/* Workaround buggy nextafterl in glibc 2.23 and earlier,
>+   see https://sourceware.org/bugzilla/show_bug.cgi?id=20205  */
>+#  define NO_LONG_DOUBLE 1
>+# endif
>+#endif
> #include "nextafter-1.c"
>
>	Jakub
Jakub Jelinek May 10, 2018, 7:12 a.m. UTC | #2
On Thu, May 10, 2018 at 07:53:15AM +0200, Richard Biener wrote:
> On May 9, 2018 10:52:05 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
> >Hi!
> >
> >glibc <= 2.23 has buggy nextafterl/nexttowardl as can be seen on the
> >nextafter-2.c testcase.
> >
> >Do we want to workaround this bug, e.g. with the following patch?
> 
> Works for me. Was the reason to test the target libc to test the compare against arithmetic? 

Yes, to verify that the GCC implementation matches the libc one.

	Jakub
diff mbox series

Patch

--- gcc/testsuite/gcc.dg/nextafter-1.c.jj	2018-05-06 23:12:48.952619545 +0200
+++ gcc/testsuite/gcc.dg/nextafter-1.c	2018-05-09 14:58:53.694198614 +0200
@@ -20,6 +20,9 @@  long double nexttowardl (long double, lo
 #ifndef NEED_EXC
 #define NEED_EXC 0
 #endif
+#ifndef NO_LONG_DOUBLE
+#define NO_LONG_DOUBLE (__LDBL_MANT_DIG__ == 106)
+#endif
 
 #define TEST(name, fn, type, L1, L2, l1, l2, MIN1,			     \
 	     MAX1, DENORM_MIN1, EPSILON1, MIN2, MAX2, DENORM_MIN2)	     \
@@ -129,7 +132,7 @@  TEST (test1, nextafterf, float, F, F, f,
 TEST (test2, nextafter, double, , , , , __DBL_MIN__, __DBL_MAX__,
       __DBL_DENORM_MIN__, __DBL_EPSILON__, __DBL_MIN__, __DBL_MAX__,
       __DBL_DENORM_MIN__)
-#if __LDBL_MANT_DIG__ != 106
+#if !NO_LONG_DOUBLE
 TEST (test3, nextafterl, long double, L, L, l, l, __LDBL_MIN__, __LDBL_MAX__,
       __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
       __LDBL_DENORM_MIN__)
@@ -149,7 +152,7 @@  main ()
 {
   test1 ();
   test2 ();
-#if __LDBL_MANT_DIG__ != 106
+#if !NO_LONG_DOUBLE
   test3 ();
   test4 ();
   test5 ();
--- gcc/testsuite/gcc.dg/nextafter-2.c.jj	2018-05-08 13:56:38.265930160 +0200
+++ gcc/testsuite/gcc.dg/nextafter-2.c	2018-05-09 14:59:45.527245803 +0200
@@ -5,4 +5,13 @@ 
 /* { dg-add-options ieee } */
 /* { dg-add-options c99_runtime } */
 
+#include <stdlib.h>
+
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+# if !__GLIBC_PREREQ (2, 24)
+/* Workaround buggy nextafterl in glibc 2.23 and earlier,
+   see https://sourceware.org/bugzilla/show_bug.cgi?id=20205  */
+#  define NO_LONG_DOUBLE 1
+# endif
+#endif
 #include "nextafter-1.c"