diff options
Diffstat (limited to 'src/include/c.h')
-rw-r--r-- | src/include/c.h | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/include/c.h b/src/include/c.h index ee615ee687f..a2d4a2c5c5d 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -156,10 +156,6 @@ #define dummyret char #endif -#ifndef __GNUC__ -#define __attribute__(_arg_) -#endif - /* ---------------------------------------------------------------- * Section 2: bool, true, false, TRUE, FALSE, NULL * ---------------------------------------------------------------- @@ -560,6 +556,47 @@ typedef NameData *Name; /* we don't currently need wider versions of the other ALIGN macros */ #define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN)) +/* ---------------- + * Attribute macros + * + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html + * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html + * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html + * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html + * ---------------- + */ + +/* only GCC supports the unused attribute */ +#ifdef __GNUC__ +#define pg_attribute_unused __attribute__((unused)) +#else +#define pg_attribute_unused +#endif + +/* GCC and XLC support format attributes */ +#if defined(__GNUC__) || defined(__IBMC__) +#define pg_attribute_format_arg(a) __attribute__((format_arg(a))) +#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a))) +#else +#define pg_attribute_format_arg(a) +#define pg_attribute_printf(f,a) +#endif + +/* GCC, Sunpro and XLC support aligned, packed and noreturn */ +#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__) +#define pg_attribute_aligned(a) __attribute__((aligned(a))) +#define pg_attribute_noreturn __attribute__((noreturn)) +#define pg_attribute_packed __attribute__((packed)) +#else +/* + * NB: aligned and packed are not defined as empty as they affect code + * functionality; they must be implemented by the compiler if they are to be + * used. + */ +#define pg_attribute_noreturn +#endif + /* ---------------------------------------------------------------- * Section 6: assertions * ---------------------------------------------------------------- @@ -906,7 +943,7 @@ typedef NameData *Name; #ifdef USE_ASSERT_CHECKING #define PG_USED_FOR_ASSERTS_ONLY #else -#define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused)) +#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused #endif @@ -973,7 +1010,7 @@ typedef NameData *Name; extern int snprintf(char *str, size_t count, const char *fmt,...) /* This extension allows gcc to check the format string */ -__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4))); +pg_attribute_printf(3, 4); #endif #if !HAVE_DECL_VSNPRINTF |