From 430e4e981ae194fd2692d88e2ed1487ed25ac697 Mon Sep 17 00:00:00 2001 From: CismonX Date: Sat, 5 Aug 2023 21:33:04 +0800 Subject: [PATCH] chore: tweak compiler builtins and attibutes * No need to use __attribute__((noreturn)) * Use __builtin_unreachable for debug asserts in non-debug builds --- configure.ac | 10 +++++----- include/arif_defs.h | 8 ++++---- src/arify_cli.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 151419b..4819c88 100644 --- a/configure.ac +++ b/configure.ac @@ -70,10 +70,9 @@ AM_CONDITIONAL([BUILD_ARIFY], [test x${enable_arify} != xno]) # -- Checks for compiler builtins and attributes -- -ARIF_TRY_APPLY([AX_GCC_FUNC_ATTRIBUTE], - [constructor], [destructor], [noreturn]) -ARIF_TRY_APPLY([AX_GCC_VAR_ATTRIBUTE], - [unused]) +ARIF_TRY_APPLY([AX_GCC_BUILTIN], [__builtin_unreachable]) +ARIF_TRY_APPLY([AX_GCC_FUNC_ATTRIBUTE], [constructor], [destructor]) +ARIF_TRY_APPLY([AX_GCC_VAR_ATTRIBUTE], [unused]) # -- Checks for header files -- @@ -85,7 +84,8 @@ AC_CHECK_HEADER_STDBOOL AC_C_INLINE AC_TYPE_SIZE_T -# -- Checks for library functions. +# -- Checks for library functions + AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([atexit memchr strcasecmp]) diff --git a/include/arif_defs.h b/include/arif_defs.h index 000133c..d679275 100644 --- a/include/arif_defs.h +++ b/include/arif_defs.h @@ -20,10 +20,10 @@ * along with ARIF. If not, see . */ -#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN -# define ARIF_NORETURN __attribute__((noreturn)) +#ifdef HAVE__BUILTIN_UNREACHABLE +# define ARIF_UNREACHABLE() __builtin_unreachable() #else -# define ARIF_NORETURN +# define ARIF_UNREACHABLE() #endif #ifdef HAVE_VAR_ATTRIBUTE_UNUSED @@ -44,5 +44,5 @@ #ifdef ARIF_DEBUG # define ARIF_DEBUG_ASSERT(expr) assert(expr) #else -# define ARIF_DEBUG_ASSERT(expr) +# define ARIF_DEBUG_ASSERT(expr) if (!(expr)) { ARIF_UNREACHABLE(); } #endif diff --git a/src/arify_cli.c b/src/arify_cli.c index d3d73f0..3bdb907 100644 --- a/src/arify_cli.c +++ b/src/arify_cli.c @@ -54,7 +54,7 @@ struct options { static void append_str (char const *, char **, char); static char * concat_str (char const *, char const *, char); static int parse_options (int, char *const [], struct options *); -static void print_usage (char const *) ARIF_NORETURN; +static void print_usage (char const *); static void set_envs (struct options *); // Forward declaration end