From 537b7695c26b9ad83ccc13b68c78a2fb27545d7e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 24 Jun 2014 16:21:58 -0400 Subject: Fix some warnings found by clang. --- libdimension/compiler-internal.h | 45 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'libdimension/compiler-internal.h') diff --git a/libdimension/compiler-internal.h b/libdimension/compiler-internal.h index ffe8de3..8b35b4a 100644 --- a/libdimension/compiler-internal.h +++ b/libdimension/compiler-internal.h @@ -23,14 +23,26 @@ * Internally-used compiler abstractions. */ -#include +#include +/** + * @def dmnsn_likely + * Indicate that a test is likely to succeed. + * @param test The test to perform. + * @return The truth value of \p test. + */ +/** + * @def dmnsn_unlikely + * Indicate that a test is unlikely to succeed. + * @param test The test to perform. + * @return The truth value of \p test. + */ #ifdef DMNSN_PROFILE #define dmnsn_likely(test) \ dmnsn_expect(!!(test), true, DMNSN_FUNC, __FILE__, __LINE__) #define dmnsn_unlikely(test) \ dmnsn_expect(!!(test), false, DMNSN_FUNC, __FILE__, __LINE__) -#elif defined(__GNUC__) +#elif DMNSN_GNUC #define dmnsn_likely(test) __builtin_expect(!!(test), true) #define dmnsn_unlikely(test) __builtin_expect(!!(test), false) #else @@ -38,7 +50,24 @@ #define dmnsn_unlikely(test) (!!(test)) #endif -#ifdef __GNUC__ +/** + * @def DMNSN_HOT + * Mark a function as a hot path. + */ +/** + * @def DMNSN_INTERNAL + * Mark a function as internal linkage. + */ +/** + * @def DMNSN_DESTRUCTOR + * Queue a function to run at program termination. + */ +/** + * @def DMNSN_LATE_DESTRUCTOR + * Queue a function to run at program termination, after those labeled + * DMNSN_DESTRUCTOR. + */ +#if DMNSN_GNUC #define DMNSN_HOT __attribute__((hot)) #define DMNSN_INTERNAL __attribute__((visibility("hidden"))) #define DMNSN_DESTRUCTOR __attribute__((destructor(102))) @@ -50,4 +79,14 @@ #define DMNSN_LATE_DESTRUCTOR #endif +/// Synonym for _Atomic that stdatomic.h doesn't define for some reason #define atomic _Atomic + +/// C11-compliant alloca variant +#define DMNSN_ALLOCA(var, size) DMNSN_ALLOCA_IMPL(var, size, __LINE__) + +#define DMNSN_ALLOCA_IMPL(var, size, ctr) DMNSN_ALLOCA_IMPL2(var, size, ctr) + +#define DMNSN_ALLOCA_IMPL2(var, size, ctr) \ + alignas(max_align_t) char dmnsn_alloca##ctr[size]; \ + var = (void *)dmnsn_alloca##ctr -- cgit v1.2.3