From: Bruno Haible Date: Sun, 9 Aug 2020 10:09:17 +0000 (+0200) Subject: Use __builtin_isnan with clang. X-Git-Tag: v1.0~3802 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a3696e42ca6813851543aa1eb43abcf37c2f31e6;p=gnulib.git Use __builtin_isnan with clang. * lib/isnanf-nolibm.h (isnanf): Use the GCC built-in __builtin_isnan, not __builtin_isnanf. Also on clang. * m4/isnanf.m4 (gl_HAVE_ISNANF_NO_LIBM, gl_ISNANF_WORKS): Use the GCC built-in __builtin_isnan, not __builtin_isnanf. Also on clang. * lib/isnand-nolibm.h (isnand): With clang, use the GCC built-in. * m4/isnand.m4 (gl_HAVE_ISNAND_IN_LIBM): With clang, use the GCC built-in. * lib/isnanl-nolibm.h (isnanf): Use the GCC built-in __builtin_isnan, not __builtin_isnanl. Also on clang. * m4/isnanl.m4 (gl_HAVE_ISNANL_NO_LIBM, gl_FUNC_ISNANL_WORKS): Use the GCC built-in __builtin_isnan, not __builtin_isnanl. Also on clang. * lib/math.in.h (__has_builtin): Remove macro. (isnanf, gl_isnan_f): Use the GCC built-in __builtin_isnan, not __builtin_isnanf. Also on clang. (isnand, gl_isnan_d): With clang, use the GCC built-in. (isnanl, gl_isnan_l): Use the GCC built-in __builtin_isnan, not __builtin_isnanl. Also on clang. (isnan): Use the GCC built-in __builtin_isnan in all three cases. Also on clang. --- diff --git a/ChangeLog b/ChangeLog index ab4cc112d2..c7fe4cae17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2020-08-09 Bruno Haible + + Use __builtin_isnan with clang. + * lib/isnanf-nolibm.h (isnanf): Use the GCC built-in __builtin_isnan, + not __builtin_isnanf. Also on clang. + * m4/isnanf.m4 (gl_HAVE_ISNANF_NO_LIBM, gl_ISNANF_WORKS): Use the GCC + built-in __builtin_isnan, not __builtin_isnanf. Also on clang. + * lib/isnand-nolibm.h (isnand): With clang, use the GCC built-in. + * m4/isnand.m4 (gl_HAVE_ISNAND_IN_LIBM): With clang, use the GCC + built-in. + * lib/isnanl-nolibm.h (isnanf): Use the GCC built-in __builtin_isnan, + not __builtin_isnanl. Also on clang. + * m4/isnanl.m4 (gl_HAVE_ISNANL_NO_LIBM, gl_FUNC_ISNANL_WORKS): Use the + GCC built-in __builtin_isnan, not __builtin_isnanl. Also on clang. + * lib/math.in.h (__has_builtin): Remove macro. + (isnanf, gl_isnan_f): Use the GCC built-in __builtin_isnan, not + __builtin_isnanf. Also on clang. + (isnand, gl_isnan_d): With clang, use the GCC built-in. + (isnanl, gl_isnan_l): Use the GCC built-in __builtin_isnan, not + __builtin_isnanl. Also on clang. + (isnan): Use the GCC built-in __builtin_isnan in all three cases. Also + on clang. + 2020-08-09 Bruno Haible thread-optim: Fix logic error. diff --git a/lib/isnand-nolibm.h b/lib/isnand-nolibm.h index cbabed4c10..b3003c6ea3 100644 --- a/lib/isnand-nolibm.h +++ b/lib/isnand-nolibm.h @@ -17,8 +17,8 @@ #if HAVE_ISNAND_IN_LIBC /* Get declaration of isnan macro. */ # include -# if __GNUC__ >= 4 - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */ # undef isnand # define isnand(x) __builtin_isnan ((double)(x)) # else diff --git a/lib/isnanf-nolibm.h b/lib/isnanf-nolibm.h index 17a2f5e0c3..be1f8b88fd 100644 --- a/lib/isnanf-nolibm.h +++ b/lib/isnanf-nolibm.h @@ -17,13 +17,11 @@ #if HAVE_ISNANF_IN_LIBC /* Get declaration of isnan macro or (older) isnanf function. */ # include -# ifndef __has_builtin -# define __has_builtin(name) 0 -# endif -# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. + GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't. */ # undef isnanf -# define isnanf(x) __builtin_isnanf ((float)(x)) +# define isnanf(x) __builtin_isnan ((float)(x)) # elif defined isnan # undef isnanf # define isnanf(x) isnan ((float)(x)) diff --git a/lib/isnanl-nolibm.h b/lib/isnanl-nolibm.h index 103d31a706..927918ca66 100644 --- a/lib/isnanl-nolibm.h +++ b/lib/isnanl-nolibm.h @@ -17,13 +17,11 @@ #if HAVE_ISNANL_IN_LIBC /* Get declaration of isnan macro or (older) isnanl function. */ # include -# ifndef __has_builtin -# define __has_builtin(name) 0 -# endif -# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. + GCC >= 4.0 also provides __builtin_isnanl, but clang doesn't. */ # undef isnanl -# define isnanl(x) __builtin_isnanl ((long double)(x)) +# define isnanl(x) __builtin_isnan ((long double)(x)) # elif defined isnan # undef isnanl # define isnanl(x) isnan ((long double)(x)) diff --git a/lib/math.in.h b/lib/math.in.h index 30465f8b2e..10514f1735 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -127,12 +127,6 @@ static void (*_gl_math_fix_itold) (long double *, int) = _Qp_itoq; #endif -/* For clang: Use __has_builtin to determine whether a builtin is available. */ -#ifndef __has_builtin -# define __has_builtin(name) 0 -#endif - - /* POSIX allows platforms that don't support NAN. But all major machines in the past 15 years have supported something close to IEEE NaN, so we define this unconditionally. We also must define @@ -2324,10 +2318,11 @@ _GL_WARN_REAL_FLOATING_DECL (isinf); # if @HAVE_ISNANF@ /* The original included above provides a declaration of isnan macro or (older) isnanf function. */ -# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. + GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't. */ # undef isnanf -# define isnanf(x) __builtin_isnanf ((float)(x)) +# define isnanf(x) __builtin_isnan ((float)(x)) # elif defined isnan # undef isnanf # define isnanf(x) isnan ((float)(x)) @@ -2347,8 +2342,8 @@ _GL_EXTERN_C int isnanf (float x); # if @HAVE_ISNAND@ /* The original included above provides a declaration of isnan macro. */ -# if __GNUC__ >= 4 - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */ # undef isnand # define isnand(x) __builtin_isnan ((double)(x)) # else @@ -2368,10 +2363,11 @@ _GL_EXTERN_C int isnand (double x); # if @HAVE_ISNANL@ /* The original included above provides a declaration of isnan macro or (older) isnanl function. */ -# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) - /* GCC 4.0 and newer provides three built-ins for isnan. */ +# if (__GNUC__ >= 4) || (__clang_major__ >= 4) + /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. + GCC >= 4.0 also provides __builtin_isnanl, but clang doesn't. */ # undef isnanl -# define isnanl(x) __builtin_isnanl ((long double)(x)) +# define isnanl(x) __builtin_isnan ((long double)(x)) # elif defined isnan # undef isnanl # define isnanl(x) isnan ((long double)(x)) @@ -2391,20 +2387,20 @@ _GL_EXTERN_C int isnanl (long double x) _GL_ATTRIBUTE_CONST; isnanf.h (e.g.) here, because those may end up being macros that recursively expand back to isnan. So use the gnulib replacements for them directly. */ -# if @HAVE_ISNANF@ && __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) -# define gl_isnan_f(x) __builtin_isnanf ((float)(x)) +# if @HAVE_ISNANF@ && (__GNUC__ >= 4) || (__clang_major__ >= 4) +# define gl_isnan_f(x) __builtin_isnan ((float)(x)) # else _GL_EXTERN_C int rpl_isnanf (float x); # define gl_isnan_f(x) rpl_isnanf (x) # endif -# if @HAVE_ISNAND@ && __GNUC__ >= 4 +# if @HAVE_ISNAND@ && (__GNUC__ >= 4) || (__clang_major__ >= 4) # define gl_isnan_d(x) __builtin_isnan ((double)(x)) # else _GL_EXTERN_C int rpl_isnand (double x); # define gl_isnan_d(x) rpl_isnand (x) # endif -# if @HAVE_ISNANL@ && __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) -# define gl_isnan_l(x) __builtin_isnanl ((long double)(x)) +# if @HAVE_ISNANL@ && (__GNUC__ >= 4) || (__clang_major__ >= 4) +# define gl_isnan_l(x) __builtin_isnan ((long double)(x)) # else _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; # define gl_isnan_l(x) rpl_isnanl (x) @@ -2414,12 +2410,12 @@ _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \ sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \ gl_isnan_f (x)) -# elif __GNUC__ >= 4 && (!defined __clang__ || (__has_builtin (__builtin_isnanf) && __has_builtin (__builtin_isnanl))) +# elif (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnan # define isnan(x) \ - (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \ + (sizeof (x) == sizeof (long double) ? __builtin_isnan ((long double)(x)) : \ sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \ - __builtin_isnanf ((float)(x))) + __builtin_isnan ((float)(x))) # endif # ifdef __cplusplus # if defined isnan || defined GNULIB_NAMESPACE diff --git a/m4/isnand.m4 b/m4/isnand.m4 index c74795ecd0..8d1841d5ae 100644 --- a/m4/isnand.m4 +++ b/m4/isnand.m4 @@ -1,4 +1,4 @@ -# isnand.m4 serial 11 +# isnand.m4 serial 12 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -58,7 +58,7 @@ AC_DEFUN([gl_HAVE_ISNAND_IN_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnand # define isnand(x) __builtin_isnan ((double)(x)) #elif defined isnan @@ -81,7 +81,7 @@ AC_DEFUN([gl_HAVE_ISNAND_NO_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnand # define isnand(x) __builtin_isnan ((double)(x)) #else diff --git a/m4/isnanf.m4 b/m4/isnanf.m4 index 7dd67bd8b4..3863aa159c 100644 --- a/m4/isnanf.m4 +++ b/m4/isnanf.m4 @@ -1,4 +1,4 @@ -# isnanf.m4 serial 16 +# isnanf.m4 serial 17 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -74,12 +74,9 @@ AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #ifndef __has_builtin - # define __has_builtin(name) 0 - #endif - #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanf - # define isnanf(x) __builtin_isnanf ((float)(x)) + # define isnanf(x) __builtin_isnan ((float)(x)) #elif defined isnan # undef isnanf # define isnanf(x) isnan ((float)(x)) @@ -102,12 +99,9 @@ AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #ifndef __has_builtin - # define __has_builtin(name) 0 - #endif - #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanf - # define isnanf(x) __builtin_isnanf ((float)(x)) + # define isnanf(x) __builtin_isnan ((float)(x)) #elif defined isnan # undef isnanf # define isnanf(x) isnan ((float)(x)) @@ -133,12 +127,9 @@ AC_DEFUN([gl_ISNANF_WORKS], AC_RUN_IFELSE( [AC_LANG_SOURCE([[ #include -#ifndef __has_builtin -# define __has_builtin(name) 0 -#endif -#if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) +#if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanf -# define isnanf(x) __builtin_isnanf ((float)(x)) +# define isnanf(x) __builtin_isnan ((float)(x)) #elif defined isnan # undef isnanf # define isnanf(x) isnan ((float)(x)) diff --git a/m4/isnanl.m4 b/m4/isnanl.m4 index 75d5462975..d50c53e16c 100644 --- a/m4/isnanl.m4 +++ b/m4/isnanl.m4 @@ -1,4 +1,4 @@ -# isnanl.m4 serial 21 +# isnanl.m4 serial 22 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -68,12 +68,9 @@ AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #ifndef __has_builtin - # define __has_builtin(name) 0 - #endif - #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanl - # define isnanl(x) __builtin_isnanl ((long double)(x)) + # define isnanl(x) __builtin_isnan ((long double)(x)) #elif defined isnan # undef isnanl # define isnanl(x) isnan ((long double)(x)) @@ -96,12 +93,9 @@ AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #ifndef __has_builtin - # define __has_builtin(name) 0 - #endif - #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) + #if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanl - # define isnanl(x) __builtin_isnanl ((long double)(x)) + # define isnanl(x) __builtin_isnan ((long double)(x)) #elif defined isnan # undef isnanl # define isnanl(x) isnan ((long double)(x)) @@ -129,12 +123,9 @@ AC_DEFUN([gl_FUNC_ISNANL_WORKS], #include #include #include -#ifndef __has_builtin -# define __has_builtin(name) 0 -#endif -#if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) +#if (__GNUC__ >= 4) || (__clang_major__ >= 4) # undef isnanl -# define isnanl(x) __builtin_isnanl ((long double)(x)) +# define isnanl(x) __builtin_isnan ((long double)(x)) #elif defined isnan # undef isnanl # define isnanl(x) isnan ((long double)(x))