From 01b5720b10727306c043327c0693203a6f77379b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 11 Aug 2020 01:53:13 +0200 Subject: [PATCH] Use many __attribute__s with clang. * m4/gnulib-common.m4 (_Noreturn): Use __attribute__ __noreturn__ also on clang. * lib/cdefs.h (__glibc_clang_has_attribute, __glibc_clang_has_builtin): New macros. (__THROW, __THROWNL, __NTH, __NTHNL): Use __attribute__ __nothrow__ also on clang. (__warndecl, __warnattr, __errordecl): Use __attribute__ __diagnose_if__ also on older clang versions. (__attribute__): Don't define to empty on clang. (__attribute_malloc__): Use __attribute__ __malloc__ also on clang. (__attribute_pure__): Use __attribute__ __pure__ also on clang. (__attribute_const__): Use __attribute__ __const__ also on clang. (__attribute_used__): Use __attribute__ __used__ also on clang. (__attribute_noinline__): Use __attribute__ __noinline__ also on clang. (__attribute_deprecated__): Use __attribute__ __deprecated__ also on clang. (__attribute_format_arg__): Use __attribute__ __format_arg__ also on clang. (__attribute_format_strfmon__): Use __attribute__ __format__ __strfmon__ also on clang. (__nonnull): Use __attribute__ __nonnull__ also on clang. (__attribute_warn_unused_result__): Use __attribute__ __warn_unused_result__ also on clang. (__always_inline): Use __attribute__ __always_inline__ also on clang. (__attribute_artificial__): Use __attribute__ __artificial__ also on clang >= 7. (__glibc_unlikely, __glibc_likely): Use __builtin_expect also on older clang versions. (_Noreturn): Don't redefine on clang >= 3.5. * lib/arg-nonnull.h (_GL_ARG_NONNULL): Use __attribute__ __nonnull__ also on clang. * lib/dirent.in.h (_GL_ATTRIBUTE_PURE): Use __attribute__ __pure__ also on clang. * lib/stdlib.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/string.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/wchar.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/stdio.in.h (_GL_ATTRIBUTE_FORMAT): Use __attribute__ __format__ also on clang. * lib/monetary.in.h (_GL_ATTRIBUTE_FORMAT): Likewise. * lib/textstyle.in.h (ostream_printf, ostream_vprintf): Likewise. * lib/unitypes.in.h (_UC_ATTRIBUTE_CONST): Use __attribute__ __const__ also on clang. (_UC_ATTRIBUTE_PURE): Use __attribute__ __pure__ also on clang. * lib/noreturn.h (_GL_NORETURN_FUNC, _GL_NORETURN_FUNCPTR): Use __attribute__ __noreturn__ also on clang. * lib/obstack.h (__attribute_noreturn__): Likewise. * lib/file-set.h (record_file): Use __attribute__ __nonnull__ also on clang. * lib/argp-help.c (hol_entry_long_iterate): Use __attribute__ always_inline also on clang. * tests/test-printf-posix.c (func1, func2, func3, func4): Test also on clang. --- ChangeLog | 56 ++++++++++++++++++++++++++ lib/arg-nonnull.h | 2 +- lib/argp-help.c | 2 +- lib/cdefs.h | 82 ++++++++++++++++++++++++--------------- lib/dirent.in.h | 2 +- lib/file-set.h | 4 +- lib/monetary.in.h | 2 +- lib/noreturn.h | 2 + lib/obstack.h | 2 +- lib/stdio.in.h | 2 +- lib/stdlib.in.h | 2 +- lib/string.in.h | 2 +- lib/textstyle.in.h | 4 +- lib/unitypes.in.h | 4 +- lib/wchar.in.h | 2 +- m4/gnulib-common.m4 | 4 +- tests/test-printf-posix.c | 2 +- 17 files changed, 127 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2efe29dfb9..3465570c19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2020-08-10 Bruno Haible + + Use many __attribute__s with clang. + * m4/gnulib-common.m4 (_Noreturn): Use __attribute__ __noreturn__ also + on clang. + * lib/cdefs.h (__glibc_clang_has_attribute, __glibc_clang_has_builtin): + New macros. + (__THROW, __THROWNL, __NTH, __NTHNL): Use __attribute__ __nothrow__ also + on clang. + (__warndecl, __warnattr, __errordecl): Use __attribute__ __diagnose_if__ + also on older clang versions. + (__attribute__): Don't define to empty on clang. + (__attribute_malloc__): Use __attribute__ __malloc__ also on clang. + (__attribute_pure__): Use __attribute__ __pure__ also on clang. + (__attribute_const__): Use __attribute__ __const__ also on clang. + (__attribute_used__): Use __attribute__ __used__ also on clang. + (__attribute_noinline__): Use __attribute__ __noinline__ also on clang. + (__attribute_deprecated__): Use __attribute__ __deprecated__ also on + clang. + (__attribute_format_arg__): Use __attribute__ __format_arg__ also on + clang. + (__attribute_format_strfmon__): Use __attribute__ __format__ __strfmon__ + also on clang. + (__nonnull): Use __attribute__ __nonnull__ also on clang. + (__attribute_warn_unused_result__): Use __attribute__ + __warn_unused_result__ also on clang. + (__always_inline): Use __attribute__ __always_inline__ also on clang. + (__attribute_artificial__): Use __attribute__ __artificial__ also on + clang >= 7. + (__glibc_unlikely, __glibc_likely): Use __builtin_expect also on older + clang versions. + (_Noreturn): Don't redefine on clang >= 3.5. + * lib/arg-nonnull.h (_GL_ARG_NONNULL): Use __attribute__ __nonnull__ + also on clang. + * lib/dirent.in.h (_GL_ATTRIBUTE_PURE): Use __attribute__ __pure__ also + on clang. + * lib/stdlib.in.h (_GL_ATTRIBUTE_PURE): Likewise. + * lib/string.in.h (_GL_ATTRIBUTE_PURE): Likewise. + * lib/wchar.in.h (_GL_ATTRIBUTE_PURE): Likewise. + * lib/stdio.in.h (_GL_ATTRIBUTE_FORMAT): Use __attribute__ __format__ + also on clang. + * lib/monetary.in.h (_GL_ATTRIBUTE_FORMAT): Likewise. + * lib/textstyle.in.h (ostream_printf, ostream_vprintf): Likewise. + * lib/unitypes.in.h (_UC_ATTRIBUTE_CONST): Use __attribute__ __const__ + also on clang. + (_UC_ATTRIBUTE_PURE): Use __attribute__ __pure__ also on clang. + * lib/noreturn.h (_GL_NORETURN_FUNC, _GL_NORETURN_FUNCPTR): Use + __attribute__ __noreturn__ also on clang. + * lib/obstack.h (__attribute_noreturn__): Likewise. + * lib/file-set.h (record_file): Use __attribute__ __nonnull__ also on + clang. + * lib/argp-help.c (hol_entry_long_iterate): Use __attribute__ + always_inline also on clang. + * tests/test-printf-posix.c (func1, func2, func3, func4): Test also on + clang. + 2020-08-10 Bruno Haible c-ldtoastr tests: Fix test failure. diff --git a/lib/arg-nonnull.h b/lib/arg-nonnull.h index d4d195a1af..42d7e70b3a 100644 --- a/lib/arg-nonnull.h +++ b/lib/arg-nonnull.h @@ -18,7 +18,7 @@ that the values passed as arguments n, ..., m must be non-NULL pointers. n = 1 stands for the first argument, n = 2 for the second argument etc. */ #ifndef _GL_ARG_NONNULL -# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 +# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__ # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) # else # define _GL_ARG_NONNULL(params) diff --git a/lib/argp-help.c b/lib/argp-help.c index 02faa60f7e..9c95c16769 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -570,7 +570,7 @@ hol_entry_short_iterate (const struct hol_entry *entry, } static inline int -#if __GNUC__ >= 3 +#if (__GNUC__ >= 3) || (__clang_major__ >= 4) __attribute__ ((always_inline)) #endif hol_entry_long_iterate (const struct hol_entry *entry, diff --git a/lib/cdefs.h b/lib/cdefs.h index 801753c7f3..170d9e6340 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h @@ -34,7 +34,34 @@ #undef __P #undef __PMT -#ifdef __GNUC__ +/* 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) +#else +# define __glibc_clang_has_attribute(name) 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) +#else +# define __glibc_clang_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) +#else +# define __glibc_clang_has_extension(ext) 0 +#endif + +#if defined __GNUC__ || defined __clang__ /* All functions, except those with callbacks or those that synchronize memory, are leaf functions. */ @@ -51,7 +78,8 @@ gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions 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, 3) +# if !defined __cplusplus \ + && (__GNUC_PREREQ (3, 3) || __glibc_clang_has_attribute (__nothrow__)) # define __THROW __attribute__ ((__nothrow__ __LEAF)) # define __THROWNL __attribute__ ((__nothrow__)) # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct @@ -70,7 +98,7 @@ # endif # endif -#else /* Not GCC. */ +#else /* Not GCC or clang. */ # if (defined __cplusplus \ || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) @@ -83,16 +111,7 @@ # define __THROWNL # define __NTH(fct) fct -#endif /* GCC. */ - -/* 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) -#else -# define __glibc_clang_has_extension(ext) 0 -#endif +#endif /* GCC || clang. */ /* These two macros are not used in glibc anymore. They are kept here only because some other projects expect the macros to be defined. */ @@ -129,7 +148,7 @@ # define __warnattr(msg) __attribute__((__warning__ (msg))) # define __errordecl(name, msg) \ extern void name (void) __attribute__((__error__ (msg))) -#elif __clang_major__ >= 4 +#elif __glibc_clang_has_attribute (__diagnose_if__) # define __warndecl(name, msg) \ extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning"))) # define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning"))) @@ -200,17 +219,17 @@ */ #endif -/* GCC has various useful declarations that can be made with the - `__attribute__' syntax. All of the ways we use this do fine if - they are omitted for compilers that don't understand it. */ -#if !defined __GNUC__ || __GNUC__ < 2 +/* GCC and clang have various useful declarations that can be made with + the '__attribute__' syntax. All of the ways we use this do fine if + they are omitted for compilers that don't understand it. */ +#if !(defined __GNUC__ || defined __clang__) # define __attribute__(xyz) /* Ignore */ #endif /* At some point during the gcc 2.96 development the `malloc' 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,96) +#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__malloc__) # define __attribute_malloc__ __attribute__ ((__malloc__)) #else # define __attribute_malloc__ /* Ignore */ @@ -228,14 +247,14 @@ /* At some point during the gcc 2.96 development the `pure' 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,96) +#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__pure__) # define __attribute_pure__ __attribute__ ((__pure__)) #else # define __attribute_pure__ /* Ignore */ #endif /* This declaration tells the compiler that the value is constant. */ -#if __GNUC_PREREQ (2,5) +#if __GNUC_PREREQ (2,5) || __glibc_clang_has_attribute (__const__) # define __attribute_const__ __attribute__ ((__const__)) #else # define __attribute_const__ /* Ignore */ @@ -244,7 +263,7 @@ /* At some point during the gcc 3.1 development the `used' 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 (3,1) +#if __GNUC_PREREQ (3,1) || __glibc_clang_has_attribute (__used__) # define __attribute_used__ __attribute__ ((__used__)) # define __attribute_noinline__ __attribute__ ((__noinline__)) #else @@ -253,7 +272,7 @@ #endif /* Since version 3.2, gcc allows marking deprecated functions. */ -#if __GNUC_PREREQ (3,2) +#if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__deprecated__) # define __attribute_deprecated__ __attribute__ ((__deprecated__)) #else # define __attribute_deprecated__ /* Ignore */ @@ -276,7 +295,7 @@ If several `format_arg' attributes are given for the same function, in 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) +#if __GNUC_PREREQ (2,8) || __glibc_clang_has_attribute (__format_arg__) # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))) #else # define __attribute_format_arg__(x) /* Ignore */ @@ -286,7 +305,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) +#if __GNUC_PREREQ (2,97) || __glibc_clang_has_attribute (__format__) # define __attribute_format_strfmon__(a,b) \ __attribute__ ((__format__ (__strfmon__, a, b))) #else @@ -297,7 +316,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) +# if __GNUC_PREREQ (3,3) || __glibc_clang_has_attribute (__nonnull__) # define __nonnull(params) __attribute__ ((__nonnull__ params)) # else # define __nonnull(params) @@ -306,7 +325,7 @@ /* If fortification mode, we warn about unused results of certain function calls which can lead to problems. */ -#if __GNUC_PREREQ (3,4) +#if __GNUC_PREREQ (3,4) || __glibc_clang_has_attribute (__warn_unused_result__) # define __attribute_warn_unused_result__ \ __attribute__ ((__warn_unused_result__)) # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0 @@ -320,7 +339,7 @@ #endif /* Forces a function to be always inlined. */ -#if __GNUC_PREREQ (3,2) +#if __GNUC_PREREQ (3,2) || __glibc_clang_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. */ @@ -333,7 +352,7 @@ /* Associate error messages with the source location of the call site rather than with the source location inside the function. */ -#if __GNUC_PREREQ (4,3) +#if __GNUC_PREREQ (4,3) || __glibc_clang_has_attribute (__artificial__) # define __attribute_artificial__ __attribute__ ((__artificial__)) #else # define __attribute_artificial__ /* Ignore */ @@ -407,7 +426,7 @@ # endif #endif -#if (__GNUC__ >= 3) || (__clang_major__ >= 4) +#if (__GNUC__ >= 3) || __glibc_clang_has_builtin (__builtin_expect) # define __glibc_unlikely(cond) __builtin_expect ((cond), 0) # define __glibc_likely(cond) __builtin_expect ((cond), 1) #else @@ -423,7 +442,8 @@ #if (!defined _Noreturn \ && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ - && !__GNUC_PREREQ (4,7)) + && !(__GNUC_PREREQ (4,7) \ + || (3 < __clang_major__ + (5 <= __clang_minor__)))) # if __GNUC_PREREQ (2,8) # define _Noreturn __attribute__ ((__noreturn__)) # else diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 6fa44f0d28..23c4e05577 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -58,7 +58,7 @@ typedef struct gl_directory DIR; /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__ # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define _GL_ATTRIBUTE_PURE /* empty */ diff --git a/lib/file-set.h b/lib/file-set.h index 244951f56f..8f64a458a3 100644 --- a/lib/file-set.h +++ b/lib/file-set.h @@ -24,8 +24,8 @@ extern void record_file (Hash_table *ht, char const *file, struct stat const *stats) -#if defined __GNUC__ && ((__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3) - __attribute__ ((nonnull (2, 3))) +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__ + __attribute__ ((__nonnull__ (2, 3))) #endif ; diff --git a/lib/monetary.in.h b/lib/monetary.in.h index 40613192a4..009a5e4626 100644 --- a/lib/monetary.in.h +++ b/lib/monetary.in.h @@ -40,7 +40,7 @@ /* Like in . */ #ifndef _GL_ATTRIBUTE_FORMAT -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__ # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) # else # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ diff --git a/lib/noreturn.h b/lib/noreturn.h index 3c12962128..01b9904e13 100644 --- a/lib/noreturn.h +++ b/lib/noreturn.h @@ -62,6 +62,7 @@ _GL_NORETURN_FUNC extern void func (void); */ #if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) \ + || defined __clang__ \ || (0x5110 <= __SUNPRO_C) /* For compatibility with _GL_NORETURN_FUNCPTR on clang, use __attribute__((__noreturn__)), not _Noreturn. */ @@ -94,6 +95,7 @@ _GL_NORETURN_FUNCPTR void (*funcptr) (void); */ #if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) \ + || defined __clang__ \ || (0x5110 <= __SUNPRO_C) # define _GL_NORETURN_FUNCPTR __attribute__ ((__noreturn__)) #else diff --git a/lib/obstack.h b/lib/obstack.h index cf5338ed50..987bd3b12c 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -153,7 +153,7 @@ /* Not the same as _Noreturn, since it also works with function pointers. */ #ifndef __attribute_noreturn__ -# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C +# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ || 0x5110 <= __SUNPRO_C # define __attribute_noreturn__ __attribute__ ((__noreturn__)) # else # define __attribute_noreturn__ diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 0823e62685..f050e1024e 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -63,7 +63,7 @@ gnulib and libintl do '#define printf __printf__' when they override the 'printf' function. */ #ifndef _GL_ATTRIBUTE_FORMAT -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__ # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) # else # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 59f9e6c71d..5c598a275d 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -102,7 +102,7 @@ struct random_data /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__ # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define _GL_ATTRIBUTE_PURE /* empty */ diff --git a/lib/string.in.h b/lib/string.in.h index ef702e3aba..34b64cbfde 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -55,7 +55,7 @@ /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__ # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define _GL_ATTRIBUTE_PURE /* empty */ diff --git a/lib/textstyle.in.h b/lib/textstyle.in.h index 536b51b42a..b888378f00 100644 --- a/lib/textstyle.in.h +++ b/lib/textstyle.in.h @@ -115,7 +115,7 @@ ostream_write_str (ostream_t stream, const char *string) static inline ptrdiff_t ostream_printf (ostream_t stream, const char *format, ...) -#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined __clang__ __attribute__ ((__format__ (__printf__, 2, 3))) #endif ; @@ -140,7 +140,7 @@ ostream_printf (ostream_t stream, const char *format, ...) static inline ptrdiff_t ostream_vprintf (ostream_t stream, const char *format, va_list args) -#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined __clang__ __attribute__ ((__format__ (__printf__, 2, 0))) #endif ; diff --git a/lib/unitypes.in.h b/lib/unitypes.in.h index 5fff76a5a5..b11326dacb 100644 --- a/lib/unitypes.in.h +++ b/lib/unitypes.in.h @@ -26,7 +26,7 @@ typedef uint32_t ucs4_t; /* Attribute of a function whose result depends only on the arguments (not pointers!) and which has no side effects. */ #ifndef _UC_ATTRIBUTE_CONST -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined __clang__ # define _UC_ATTRIBUTE_CONST __attribute__ ((__const__)) # else # define _UC_ATTRIBUTE_CONST @@ -36,7 +36,7 @@ typedef uint32_t ucs4_t; /* Attribute of a function whose result depends only on the arguments (possibly pointers) and global memory, and which has no side effects. */ #ifndef _UC_ATTRIBUTE_PURE -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__ # define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define _UC_ATTRIBUTE_PURE diff --git a/lib/wchar.in.h b/lib/wchar.in.h index bfcf611df6..e52453359f 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -95,7 +95,7 @@ /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__ # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define _GL_ATTRIBUTE_PURE /* empty */ diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index e42b80cf61..03da2287d4 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 54 +# gnulib-common.m4 serial 55 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, @@ -45,7 +45,7 @@ AC_DEFUN([gl_COMMON_BODY], [ ? 6000000 <= __apple_build_version__ \ : 3 < __clang_major__ + (5 <= __clang_minor__)))) /* _Noreturn works as-is. */ -# elif _GL_GNUC_PREREQ (2, 8) || 0x5110 <= __SUNPRO_C +# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C # define _Noreturn __attribute__ ((__noreturn__)) # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) # define _Noreturn __declspec (noreturn) diff --git a/tests/test-printf-posix.c b/tests/test-printf-posix.c index 124587a6a4..b0af595aec 100644 --- a/tests/test-printf-posix.c +++ b/tests/test-printf-posix.c @@ -39,7 +39,7 @@ main (int argc, char *argv[]) } /* Test whether __attribute__ (__format__ (...)) still works. */ -#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !defined __STRICT_ANSI__ +#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__) && !defined __STRICT_ANSI__ extern int func1 (char *, size_t, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern int func2 (char *, size_t, const char *, ...) -- 2.39.5