From fb996ebaa937d411991b1f1a214a3711e6403f38 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 5 May 2022 13:53:13 +0800 Subject: [PATCH] compiler.h: Move c++ standard feature out of compiler specific section and correct the code indent Signed-off-by: Xiang Xiao --- include/nuttx/compiler.h | 272 +++++++++++++++++---------------------- 1 file changed, 119 insertions(+), 153 deletions(-) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 3ba3936f2f..c75660f80c 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -31,6 +31,36 @@ * Pre-processor Definitions ****************************************************************************/ +/* ISO C11 supports anonymous (unnamed) structures and unions, added in + * GCC 4.6 (but might be suppressed with -std= option). ISO C++11 also + * adds un-named unions, but NOT unnamed structures (although compilers + * may support them). + * + * CAREFUL: This can cause issues for shared data structures shared between + * C and C++ if the two versions do not support the same features. + * Structures and unions can lose binary compatibility! + * + * NOTE: The NuttX coding standard forbids the use of unnamed structures and + * unions within the OS. + */ + +#undef CONFIG_HAVE_ANONYMOUS_STRUCT +#undef CONFIG_HAVE_ANONYMOUS_UNION + +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +# define CONFIG_HAVE_ANONYMOUS_STRUCT 1 +# define CONFIG_HAVE_ANONYMOUS_UNION 1 +#endif + +/* C++ support */ + +#if defined(__cplusplus) && __cplusplus >= 201402L +# define CONFIG_HAVE_CXX14 1 +#else +# undef CONFIG_HAVE_CXX14 +#endif + /* GCC-specific definitions *************************************************/ #ifdef __GNUC__ @@ -71,19 +101,11 @@ * undefined and needs to be taken care of by the caller. */ -#if __GNUC__ >= 4 -# define CONFIG_HAVE_BUILTIN_CTZ 1 -# define CONFIG_HAVE_BUILTIN_CLZ 1 -# define CONFIG_HAVE_BUILTIN_POPCOUNT 1 -#endif - -/* C++ support */ - -#if defined(__cplusplus) && __cplusplus >= 201402L -# define CONFIG_HAVE_CXX14 1 -#else -# undef CONFIG_HAVE_CXX14 -#endif +# if __GNUC__ >= 4 +# define CONFIG_HAVE_BUILTIN_CTZ 1 +# define CONFIG_HAVE_BUILTIN_CLZ 1 +# define CONFIG_HAVE_BUILTIN_POPCOUNT 1 +# endif /* Attributes * @@ -91,20 +113,20 @@ * unnecessary "weak" functions can be excluded from the link. */ -# if !defined(__CYGWIN__) && !defined(CONFIG_ARCH_GNU_NO_WEAKFUNCTIONS) -# define CONFIG_HAVE_WEAKFUNCTIONS 1 -# define weak_alias(name, aliasname) \ - extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); -# define weak_data __attribute__ ((weak)) -# define weak_function __attribute__ ((weak)) -# define weak_const_function __attribute__ ((weak, __const__)) -# else -# undef CONFIG_HAVE_WEAKFUNCTIONS -# define weak_alias(name, aliasname) -# define weak_data -# define weak_function -# define weak_const_function -# endif +# if !defined(__CYGWIN__) && !defined(CONFIG_ARCH_GNU_NO_WEAKFUNCTIONS) +# define CONFIG_HAVE_WEAKFUNCTIONS 1 +# define weak_alias(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); +# define weak_data __attribute__ ((weak)) +# define weak_function __attribute__ ((weak)) +# define weak_const_function __attribute__ ((weak, __const__)) +# else +# undef CONFIG_HAVE_WEAKFUNCTIONS +# define weak_alias(name, aliasname) +# define weak_data +# define weak_function +# define weak_const_function +# endif /* The noreturn attribute informs GCC that the function will not return. * C11 adds _Noreturn keyword (see stdnoreturn.h) @@ -163,24 +185,24 @@ * sensitive functions, e.g., stack coloration routines. */ -#if defined(__has_attribute) -# if __has_attribute(no_stack_protector) -# define nostackprotect_function __attribute__ ((no_stack_protector)) +# if defined(__has_attribute) +# if __has_attribute(no_stack_protector) +# define nostackprotect_function __attribute__ ((no_stack_protector)) +# endif # endif -#endif /* nostackprotect_function definition for older versions of GCC and Clang. * Note that Clang does not support setting per-function optimizations, * simply disable the entire optimization pass for the required function. */ -#ifndef nostackprotect_function -# if defined(__clang__) -# define nostackprotect_function __attribute__ ((optnone)) -# else -# define nostackprotect_function __attribute__ ((__optimize__("-fno-stack-protector"))) +# ifndef nostackprotect_function +# if defined(__clang__) +# define nostackprotect_function __attribute__ ((optnone)) +# else +# define nostackprotect_function __attribute__ ((__optimize__("-fno-stack-protector"))) +# endif # endif -#endif /* The unused code or data */ @@ -222,155 +244,133 @@ * pointers are 16-bits. */ -#if defined(__m32c__) +# if defined(__m32c__) /* No I-space access qualifiers */ -# define IOBJ -# define IPTR +# define IOBJ +# define IPTR /* Select the small, 16-bit addressing model */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Long and int are not the same size */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size */ -# undef CONFIG_PTR_IS_NOT_INT +# undef CONFIG_PTR_IS_NOT_INT -#elif defined(__AVR__) -# if defined(CONFIG_AVR_HAS_MEMX_PTR) - /* I-space access qualifiers needed by Harvard architecture */ +# elif defined(__AVR__) +# if defined(CONFIG_AVR_HAS_MEMX_PTR) +/* I-space access qualifiers needed by Harvard architecture */ -# define IOBJ __flash -# define IPTR __memx +# define IOBJ __flash +# define IPTR __memx -# else +# else /* No I-space access qualifiers */ -# define IOBJ -# define IPTR -# endif +# define IOBJ +# define IPTR +# endif /* Select the small, 16-bit addressing model (for D-Space) */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Long and int are not the same size */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size */ -# undef CONFIG_PTR_IS_NOT_INT +# undef CONFIG_PTR_IS_NOT_INT /* Uses a 32-bit FAR pointer only from accessing data outside of the 16-bit * data space. */ -# define CONFIG_HAVE_FARPOINTER 1 +# define CONFIG_HAVE_FARPOINTER 1 -#elif defined(__mc68hc1x__) +# elif defined(__mc68hc1x__) /* No I-space access qualifiers */ -# define IOBJ -# define IPTR +# define IOBJ +# define IPTR /* Select the small, 16-bit addressing model */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Normally, mc68hc1x code is compiled with the -mshort option * which results in a 16-bit integer. If -mnoshort is defined * then an integer is 32-bits. GCC will defined __INT__ accordingly: */ -# if __INT__ == 16 +# if __INT__ == 16 /* int is 16-bits, long is 32-bits */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size (16-bits) */ -# undef CONFIG_PTR_IS_NOT_INT -# else +# undef CONFIG_PTR_IS_NOT_INT +# else /* int and long are both 32-bits */ -# undef CONFIG_LONG_IS_NOT_INT +# undef CONFIG_LONG_IS_NOT_INT /* Pointers and int are NOT the same size */ -# define CONFIG_PTR_IS_NOT_INT 1 -# endif +# define CONFIG_PTR_IS_NOT_INT 1 +# endif -#elif defined(_EZ80ACCLAIM) +# elif defined(_EZ80ACCLAIM) /* No I-space access qualifiers */ -# define IOBJ -# define IPTR +# define IOBJ +# define IPTR /* Select the large, 24-bit addressing model */ -# undef CONFIG_SMALL_MEMORY +# undef CONFIG_SMALL_MEMORY /* int is 24-bits, long is 32-bits */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* pointers are 24-bits too */ -# undef CONFIG_PTR_IS_NOT_INT +# undef CONFIG_PTR_IS_NOT_INT /* the ez80 stdlib doesn't support doubles */ -# undef CONFIG_HAVE_DOUBLE -# undef CONFIG_HAVE_LONG_DOUBLE +# undef CONFIG_HAVE_DOUBLE +# undef CONFIG_HAVE_LONG_DOUBLE -#else +# else /* No I-space access qualifiers */ -# define IOBJ -# define IPTR +# define IOBJ +# define IPTR /* Select the large, 32-bit addressing model */ -# undef CONFIG_SMALL_MEMORY +# undef CONFIG_SMALL_MEMORY /* Long and int are (probably) the same size (32-bits) */ -# undef CONFIG_LONG_IS_NOT_INT +# undef CONFIG_LONG_IS_NOT_INT /* Pointers and int are the same size (32-bits) */ -# undef CONFIG_PTR_IS_NOT_INT +# undef CONFIG_PTR_IS_NOT_INT -#endif - -/* ISO C11 supports anonymous (unnamed) structures and unions, added in - * GCC 4.6 (but might be suppressed with -std= option). ISO C++11 also - * adds un-named unions, but NOT unnamed structures (although compilers - * may support them). - * - * CAREFUL: This can cause issues for shared data structures shared between - * C and C++ if the two versions do not support the same features. - * Structures and unions can lose binary compatibility! - * - * NOTE: The NuttX coding standard forbids the use of unnamed structures and - * unions within the OS. - */ - -# undef CONFIG_HAVE_ANONYMOUS_STRUCT -# undef CONFIG_HAVE_ANONYMOUS_UNION - -# if (defined(__cplusplus) && __cplusplus >= 201103L) || \ - (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) -# define CONFIG_HAVE_ANONYMOUS_STRUCT 1 -# define CONFIG_HAVE_ANONYMOUS_UNION 1 # endif /* Indicate that a local variable is not used */ @@ -412,10 +412,6 @@ # pragma disable_warning 85 -/* C++ support */ - -# undef CONFIG_HAVE_CXX14 - /* Attributes * * SDCC does not support weak symbols @@ -477,11 +473,6 @@ # define reentrant_function __reentrant -/* ISO C11 supports anonymous (unnamed) structures and unions. Does SDCC? */ - -# undef CONFIG_HAVE_ANONYMOUS_STRUCT -# undef CONFIG_HAVE_ANONYMOUS_UNION - /* Indicate that a local variable is not used */ # define UNUSED(a) ((void)(1 || (a))) @@ -493,21 +484,21 @@ * external RAM. */ -#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_gbz80) -# define FAR -# define NEAR -# define CODE -# define DSEG -#else -# define FAR __xdata -# define NEAR __data -# define CODE __code -# if defined(SDCC_MODEL_SMALL) -# define DSEG __data +# if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_gbz80) +# define FAR +# define NEAR +# define CODE +# define DSEG # else -# define DSEG __xdata +# define FAR __xdata +# define NEAR __data +# define CODE __code +# if defined(SDCC_MODEL_SMALL) +# define DSEG __data +# else +# define DSEG __xdata +# endif # endif -#endif /* Select small, 16-bit address model */ @@ -522,9 +513,9 @@ * the same size as int than just z80 and z180. */ -#if !defined(__z80) && !defined(__gbz80) -# define CONFIG_PTR_IS_NOT_INT 1 -#endif +# if !defined(__z80) && !defined(__gbz80) +# define CONFIG_PTR_IS_NOT_INT 1 +# endif /* SDCC does types long long and float, but not types double and long * double. @@ -564,10 +555,6 @@ # define IOBJ # define IPTR -/* C++ support */ - -# undef CONFIG_HAVE_CXX14 - /* Attributes * * The Zilog compiler does not support weak symbols @@ -655,13 +642,6 @@ # endif # endif -/* ISO C11 supports anonymous (unnamed) structures and unions. Zilog does - * not support C11 - */ - -# undef CONFIG_HAVE_ANONYMOUS_STRUCT -# undef CONFIG_HAVE_ANONYMOUS_UNION - /* Indicate that a local variable is not used */ # define UNUSED(a) ((void)(1 || (a))) @@ -729,17 +709,6 @@ # pragma section = ".data_init" # pragma section = ".text" -/* C++ support */ - -# undef CONFIG_HAVE_CXX14 - -/* ISO C11 supports anonymous (unnamed) structures and unions. Does - * ICCARM? - */ - -# undef CONFIG_HAVE_ANONYMOUS_STRUCT -# undef CONFIG_HAVE_ANONYMOUS_UNION - /* Indicate that a local variable is not used */ # define UNUSED(a) ((void)(1 || (a))) @@ -761,7 +730,6 @@ # undef CONFIG_HAVE_FUNCTIONNAME # undef CONFIG_HAVE_FILENAME # undef CONFIG_HAVE_WEAKFUNCTIONS -# undef CONFIG_HAVE_CXX14 # define weak_alias(name, aliasname) # define weak_data # define weak_function @@ -802,8 +770,6 @@ # define CONFIG_HAVE_FLOAT 1 # undef CONFIG_HAVE_DOUBLE # undef CONFIG_HAVE_LONG_DOUBLE -# undef CONFIG_HAVE_ANONYMOUS_STRUCT -# undef CONFIG_HAVE_ANONYMOUS_UNION # define UNUSED(a) ((void)(1 || (a)))