[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
improve clang support (8)
From: |
Bruno Haible |
Subject: |
improve clang support (8) |
Date: |
Sun, 09 Aug 2020 12:13:18 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; ) |
clang has, like GCC, the built-in __builtin_isnan. clang does not have, however,
the built-ins __builtin_isnanf and __builtin_isnanl. But there is an easy
workaround: __builtin_isnan is in fact type-generic (works also on 'float' and
'long double' arguments), both in GCC and clang.
2020-08-09 Bruno Haible <bruno@clisp.org>
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/lib/isnand-nolibm.h b/lib/isnand-nolibm.h
index cbabed4..b3003c6 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 <math.h>
-# 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 17a2f5e..be1f8b8 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 <math.h>
-# 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 103d31a..927918c 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 <math.h>
-# 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 30465f8..10514f1 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 <math.h> 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 <math.h> 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 <math.h> 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 c74795e..8d1841d 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 <math.h>
- #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 <math.h>
- #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 7dd67bd..3863aa1 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 <math.h>
- #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 <math.h>
- #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 <math.h>
-#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 75d54629..d50c53e 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 <math.h>
- #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 <math.h>
- #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 <float.h>
#include <limits.h>
#include <math.h>
-#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))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- improve clang support (8),
Bruno Haible <=