From 665e4118cbfc611e1e9b1767f0817a5903e29e8b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 23 May 2020 21:17:22 +0200 Subject: [PATCH] isnanf, isnanl, isnan: Don't use nonexistent builtins with clang. * m4/isnanf.m4 (gl_HAVE_ISNANF_NO_LIBM, gl_HAVE_ISNANF_IN_LIBM, gl_ISNANF_WORKS): Don't use __builtin_isnanf on clang versions that don't have it. * m4/isnanl.m4 (gl_HAVE_ISNANL_NO_LIBM, gl_HAVE_ISNANL_IN_LIBM, gl_FUNC_ISNANL_WORKS): Don't use __builtin_isnanl on clang versions that don't have it. * lib/isnanf-nolibm.h (__has_builtin): New macro. (isnanf): Don't use __builtin_isnanf on clang versions that don't have it. * lib/isnanl-nolibm.h (__has_builtin): New macro. (isnanl): Don't use __builtin_isnanl on clang versions that don't have it. * lib/math.in.h (__has_builtin): New macro. (isnanf): Don't use __builtin_isnanf on clang versions that don't have it. (isnanl): Don't use __builtin_isnanl on clang versions that don't have it. (isnan): Don't use the builtins on clang versions that don't have __builtin_isnanf and __builtin_isnanl. --- ChangeLog | 23 +++++++++++++++++++++++ lib/isnanf-nolibm.h | 5 ++++- lib/isnanl-nolibm.h | 5 ++++- lib/math.in.h | 16 +++++++++++----- m4/isnanf.m4 | 17 +++++++++++++---- m4/isnanl.m4 | 17 +++++++++++++---- 6 files changed, 68 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5a1f13f45..3d4c0f8b0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2020-05-23 Bruno Haible + + isnanf, isnanl, isnan: Don't use nonexistent builtins with clang. + * m4/isnanf.m4 (gl_HAVE_ISNANF_NO_LIBM, gl_HAVE_ISNANF_IN_LIBM, + gl_ISNANF_WORKS): Don't use __builtin_isnanf on clang versions that + don't have it. + * m4/isnanl.m4 (gl_HAVE_ISNANL_NO_LIBM, gl_HAVE_ISNANL_IN_LIBM, + gl_FUNC_ISNANL_WORKS): Don't use __builtin_isnanl on clang versions that + don't have it. + * lib/isnanf-nolibm.h (__has_builtin): New macro. + (isnanf): Don't use __builtin_isnanf on clang versions that don't have + it. + * lib/isnanl-nolibm.h (__has_builtin): New macro. + (isnanl): Don't use __builtin_isnanl on clang versions that don't have + it. + * lib/math.in.h (__has_builtin): New macro. + (isnanf): Don't use __builtin_isnanf on clang versions that don't have + it. + (isnanl): Don't use __builtin_isnanl on clang versions that don't have + it. + (isnan): Don't use the builtins on clang versions that don't have + __builtin_isnanf and __builtin_isnanl. + 2020-05-23 Bruno Haible calloc-gnu: Avoid wrong configure results with clang. diff --git a/lib/isnanf-nolibm.h b/lib/isnanf-nolibm.h index 647ffeda32..17a2f5e0c3 100644 --- a/lib/isnanf-nolibm.h +++ b/lib/isnanf-nolibm.h @@ -17,7 +17,10 @@ #if HAVE_ISNANF_IN_LIBC /* Get declaration of isnan macro or (older) isnanf function. */ # include -# if __GNUC__ >= 4 +# 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. */ # undef isnanf # define isnanf(x) __builtin_isnanf ((float)(x)) diff --git a/lib/isnanl-nolibm.h b/lib/isnanl-nolibm.h index c45e3ab2c7..103d31a706 100644 --- a/lib/isnanl-nolibm.h +++ b/lib/isnanl-nolibm.h @@ -17,7 +17,10 @@ #if HAVE_ISNANL_IN_LIBC /* Get declaration of isnan macro or (older) isnanl function. */ # include -# if __GNUC__ >= 4 +# 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. */ # undef isnanl # define isnanl(x) __builtin_isnanl ((long double)(x)) diff --git a/lib/math.in.h b/lib/math.in.h index e5e37d60a1..30465f8b2e 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -127,6 +127,12 @@ 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 @@ -2318,7 +2324,7 @@ _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 +# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) /* GCC 4.0 and newer provides three built-ins for isnan. */ # undef isnanf # define isnanf(x) __builtin_isnanf ((float)(x)) @@ -2362,7 +2368,7 @@ _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 +# if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) /* GCC 4.0 and newer provides three built-ins for isnan. */ # undef isnanl # define isnanl(x) __builtin_isnanl ((long double)(x)) @@ -2385,7 +2391,7 @@ _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 +# if @HAVE_ISNANF@ && __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) # define gl_isnan_f(x) __builtin_isnanf ((float)(x)) # else _GL_EXTERN_C int rpl_isnanf (float x); @@ -2397,7 +2403,7 @@ _GL_EXTERN_C int rpl_isnanf (float x); _GL_EXTERN_C int rpl_isnand (double x); # define gl_isnan_d(x) rpl_isnand (x) # endif -# if @HAVE_ISNANL@ && __GNUC__ >= 4 +# if @HAVE_ISNANL@ && __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) # define gl_isnan_l(x) __builtin_isnanl ((long double)(x)) # else _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; @@ -2408,7 +2414,7 @@ _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 +# elif __GNUC__ >= 4 && (!defined __clang__ || (__has_builtin (__builtin_isnanf) && __has_builtin (__builtin_isnanl))) # undef isnan # define isnan(x) \ (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \ diff --git a/m4/isnanf.m4 b/m4/isnanf.m4 index 4e9fb48652..7dd67bd8b4 100644 --- a/m4/isnanf.m4 +++ b/m4/isnanf.m4 @@ -1,4 +1,4 @@ -# isnanf.m4 serial 15 +# isnanf.m4 serial 16 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,7 +74,10 @@ AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #ifndef __has_builtin + # define __has_builtin(name) 0 + #endif + #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) # undef isnanf # define isnanf(x) __builtin_isnanf ((float)(x)) #elif defined isnan @@ -99,7 +102,10 @@ AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #ifndef __has_builtin + # define __has_builtin(name) 0 + #endif + #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) # undef isnanf # define isnanf(x) __builtin_isnanf ((float)(x)) #elif defined isnan @@ -127,7 +133,10 @@ AC_DEFUN([gl_ISNANF_WORKS], AC_RUN_IFELSE( [AC_LANG_SOURCE([[ #include -#if __GNUC__ >= 4 +#ifndef __has_builtin +# define __has_builtin(name) 0 +#endif +#if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanf)) # undef isnanf # define isnanf(x) __builtin_isnanf ((float)(x)) #elif defined isnan diff --git a/m4/isnanl.m4 b/m4/isnanl.m4 index 9874418a69..75d5462975 100644 --- a/m4/isnanl.m4 +++ b/m4/isnanl.m4 @@ -1,4 +1,4 @@ -# isnanl.m4 serial 20 +# isnanl.m4 serial 21 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,7 +68,10 @@ AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #ifndef __has_builtin + # define __has_builtin(name) 0 + #endif + #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) # undef isnanl # define isnanl(x) __builtin_isnanl ((long double)(x)) #elif defined isnan @@ -93,7 +96,10 @@ AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM], AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include - #if __GNUC__ >= 4 + #ifndef __has_builtin + # define __has_builtin(name) 0 + #endif + #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) # undef isnanl # define isnanl(x) __builtin_isnanl ((long double)(x)) #elif defined isnan @@ -123,7 +129,10 @@ AC_DEFUN([gl_FUNC_ISNANL_WORKS], #include #include #include -#if __GNUC__ >= 4 +#ifndef __has_builtin +# define __has_builtin(name) 0 +#endif +#if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl)) # undef isnanl # define isnanl(x) __builtin_isnanl ((long double)(x)) #elif defined isnan -- 2.39.5