From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 818DB1F4B4 for ; Wed, 6 Jan 2021 18:07:29 +0000 (UTC) Received: from localhost ([::1]:34642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxDDU-0004Bb-MM for normalperson@yhbt.net; Wed, 06 Jan 2021 13:07:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxDDR-0004AW-Mq for bug-gnulib@gnu.org; Wed, 06 Jan 2021 13:07:25 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:43712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxDDP-0007C8-Gu for bug-gnulib@gnu.org; Wed, 06 Jan 2021 13:07:25 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 59E7D160125 for ; Wed, 6 Jan 2021 10:07:22 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id nWv5LNJkklge; Wed, 6 Jan 2021 10:07:20 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id DC3A9160129; Wed, 6 Jan 2021 10:07:20 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id USr5tfumguVF; Wed, 6 Jan 2021 10:07:20 -0800 (PST) Received: from day.example.com (cpe-23-243-218-95.socal.res.rr.com [23.243.218.95]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id AC93C16011F; Wed, 6 Jan 2021 10:07:20 -0800 (PST) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH] libc-config: simplify clang __has_* macros Date: Wed, 6 Jan 2021 10:07:16 -0800 Message-Id: <20210106180716.211055-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" cdefs.h sometimes used names like __glibc_clang_has_attribute and sometimes __glibc_has_attribute. There is no need in glibc or Gnulib to distinguish clang from other compilers here, so be consistent and use the simpler names. * lib/cdefs.h (__glibc_has_builtin, __glibc_has_extension): Rename from __glibc_clang_has_builtin, __glibc_clang_has_extension. All uses changed. (__glibc_clang_has_attribute): Remove. All uses replaced by __glibc_has_attribute. * lib/libc-config.h [!__glibc_likely]: Undef them here too. This fixes a problem where __glibc_has_attribute was not undeffed. --- ChangeLog | 15 +++++++++++ lib/cdefs.h | 69 +++++++++++++++++++---------------------------- lib/libc-config.h | 6 ++--- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c8d86059..b68667bcf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2021-01-06 Paul Eggert + + libc-config: simplify clang __has_* macros + cdefs.h sometimes used names like __glibc_clang_has_attribute and + sometimes __glibc_has_attribute. There is no need in glibc or + Gnulib to distinguish clang from other compilers here, so be + consistent and use the simpler names. + * lib/cdefs.h (__glibc_has_builtin, __glibc_has_extension): + Rename from __glibc_clang_has_builtin, __glibc_clang_has_extension. + All uses changed. + (__glibc_clang_has_attribute): Remove. All uses replaced + by __glibc_has_attribute. + * lib/libc-config.h [!__glibc_likely]: Undef them here too. + This fixes a problem where __glibc_has_attribute was not undeffed. + 2021-01-06 Bruno Haible =20 flock: Update documentation. diff --git a/lib/cdefs.h b/lib/cdefs.h index 4383e70f2..c4769aa70 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h @@ -34,31 +34,24 @@ #undef __P #undef __PMT =20 -/* Compilers that are not clang may object to - #if defined __clang__ && __has_attribute(...) - even though they do not need to evaluate the right-hand side of the &= &. */ -#if defined __clang__ && defined __has_attribute -# define __glibc_clang_has_attribute(name) __has_attribute (name) +/* Compilers that lack __has_attribute may object to + #if defined __has_attribute && __has_attribute (...) + even though they do not need to evaluate the right-hand side of the &= &. + Similarly for __has_builtin, etc. */ +#ifdef __has_attribute +# define __glibc_has_attribute(attr) __has_attribute (attr) #else -# define __glibc_clang_has_attribute(name) 0 +# define __glibc_has_attribute(attr) 0 #endif - -/* Compilers that are not clang may object to - #if defined __clang__ && __has_builtin(...) - even though they do not need to evaluate the right-hand side of the &= &. */ -#if defined __clang__ && defined __has_builtin -# define __glibc_clang_has_builtin(name) __has_builtin (name) +#ifdef __has_builtin +# define __glibc_has_builtin(name) __has_builtin (name) #else -# define __glibc_clang_has_builtin(name) 0 +# define __glibc_has_builtin(name) 0 #endif - -/* Compilers that are not clang may object to - #if defined __clang__ && __has_extension(...) - even though they do not need to evaluate the right-hand side of the &= &. */ -#if defined __clang__ && defined __has_extension -# define __glibc_clang_has_extension(ext) __has_extension (ext) +#ifdef __has_extension +# define __glibc_has_extension(ext) __has_extension (ext) #else -# define __glibc_clang_has_extension(ext) 0 +# define __glibc_has_extension(ext) 0 #endif =20 #if defined __GNUC__ || defined __clang__ @@ -79,7 +72,7 @@ as non-throwing using a function attribute since programs can use the -fexceptions options for C code as well. */ # if !defined __cplusplus \ - && (__GNUC_PREREQ (3, 4) || __glibc_clang_has_attribute (__nothrow_= _)) + && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__)) # define __THROW __attribute__ ((__nothrow__ __LEAF)) # define __THROWNL __attribute__ ((__nothrow__)) # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct @@ -233,7 +226,7 @@ /* At some point during the gcc 2.96 development the `malloc' attribute for functions was introduced. We don't want to use it unconditionall= y (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__malloc__) +#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__) # define __attribute_malloc__ __attribute__ ((__malloc__)) #else # define __attribute_malloc__ /* Ignore */ @@ -251,14 +244,14 @@ /* At some point during the gcc 2.96 development the `pure' attribute for functions was introduced. We don't want to use it unconditionall= y (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__pure__) +#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__) # define __attribute_pure__ __attribute__ ((__pure__)) #else # define __attribute_pure__ /* Ignore */ #endif =20 /* This declaration tells the compiler that the value is constant. */ -#if __GNUC_PREREQ (2,5) || __glibc_clang_has_attribute (__const__) +#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__) # define __attribute_const__ __attribute__ ((__const__)) #else # define __attribute_const__ /* Ignore */ @@ -267,7 +260,7 @@ /* At some point during the gcc 3.1 development the `used' attribute for functions was introduced. We don't want to use it unconditionall= y (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (3,1) || __glibc_clang_has_attribute (__used__) +#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__) # define __attribute_used__ __attribute__ ((__used__)) # define __attribute_noinline__ __attribute__ ((__noinline__)) #else @@ -276,7 +269,7 @@ #endif =20 /* Since version 3.2, gcc allows marking deprecated functions. */ -#if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__deprecated__) +#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__) # define __attribute_deprecated__ __attribute__ ((__deprecated__)) #else # define __attribute_deprecated__ /* Ignore */ @@ -286,7 +279,7 @@ when a deprecated function is used. clang claims to be gcc 4.2, but may also support this feature. */ #if __GNUC_PREREQ (4,5) \ - || __glibc_clang_has_extension (__attribute_deprecated_with_message_= _) + || __glibc_has_extension (__attribute_deprecated_with_message__) # define __attribute_deprecated_msg__(msg) \ __attribute__ ((__deprecated__ (msg))) #else @@ -299,7 +292,7 @@ If several `format_arg' attributes are given for the same function, i= n gcc-3.0 and older, all but the last one are ignored. In newer gccs, all designated arguments are considered. */ -#if __GNUC_PREREQ (2,8) || __glibc_clang_has_attribute (__format_arg__) +#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__) # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))= ) #else # define __attribute_format_arg__(x) /* Ignore */ @@ -309,7 +302,7 @@ attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,97) || __glibc_clang_has_attribute (__format__) +#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__) # define __attribute_format_strfmon__(a,b) \ __attribute__ ((__format__ (__strfmon__, a, b))) #else @@ -320,7 +313,7 @@ must not be NULL. Do not define __nonnull if it is already defined, for portability when this file is used in Gnulib. */ #ifndef __nonnull -# if __GNUC_PREREQ (3,3) || __glibc_clang_has_attribute (__nonnull__) +# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__) # define __nonnull(params) __attribute__ ((__nonnull__ params)) # else # define __nonnull(params) @@ -329,7 +322,7 @@ =20 /* If fortification mode, we warn about unused results of certain function calls which can lead to problems. */ -#if __GNUC_PREREQ (3,4) || __glibc_clang_has_attribute (__warn_unused_re= sult__) +#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__= ) # define __attribute_warn_unused_result__ \ __attribute__ ((__warn_unused_result__)) # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0 @@ -343,7 +336,7 @@ #endif =20 /* Forces a function to be always inlined. */ -#if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__always_inline_= _) +#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__) /* The Linux kernel defines __always_inline in stddef.h (283d7573), and it conflicts with this definition. Therefore undefine it first to allow either header to be included first. */ @@ -356,7 +349,7 @@ =20 /* Associate error messages with the source location of the call site ra= ther than with the source location inside the function. */ -#if __GNUC_PREREQ (4,3) || __glibc_clang_has_attribute (__artificial__) +#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__) # define __attribute_artificial__ __attribute__ ((__artificial__)) #else # define __attribute_artificial__ /* Ignore */ @@ -433,7 +426,7 @@ # endif #endif =20 -#if (__GNUC__ >=3D 3) || __glibc_clang_has_builtin (__builtin_expect) +#if (__GNUC__ >=3D 3) || __glibc_has_builtin (__builtin_expect) # define __glibc_unlikely(cond) __builtin_expect ((cond), 0) # define __glibc_likely(cond) __builtin_expect ((cond), 1) #else @@ -441,12 +434,6 @@ # define __glibc_likely(cond) (cond) #endif =20 -#ifdef __has_attribute -# define __glibc_has_attribute(attr) __has_attribute (attr) -#else -# define __glibc_has_attribute(attr) 0 -#endif - #if (!defined _Noreturn \ && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ && !(__GNUC_PREREQ (4,7) \ @@ -581,7 +568,7 @@ _Static_assert (0, "IEEE 128-bits long double require= s redirection on this platf check is required to enable the use of generic selection. */ #if !defined __cplusplus \ && (__GNUC_PREREQ (4, 9) \ - || __glibc_clang_has_extension (c_generic_selections) \ + || __glibc_has_extension (c_generic_selections) \ || (!defined __GNUC__ && defined __STDC_VERSION__ \ && __STDC_VERSION__ >=3D 201112L)) # define __HAVE_GENERIC_SELECTION 1 diff --git a/lib/libc-config.h b/lib/libc-config.h index 18fb722dc..19e852f45 100644 --- a/lib/libc-config.h +++ b/lib/libc-config.h @@ -144,9 +144,9 @@ # undef __flexarr # undef __fortify_function # undef __glibc_c99_flexarr_available -# undef __glibc_clang_has_attribute -# undef __glibc_clang_has_builtin -# undef __glibc_clang_has_extension +# undef __glibc_has_attribute +# undef __glibc_has_builtin +# undef __glibc_has_extension # undef __glibc_macro_warning # undef __glibc_macro_warning1 # undef __glibc_objsize --=20 2.27.0