summaryrefslogtreecommitdiffstats
path: root/libdimension/compiler-internal.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-06-24 16:21:58 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-06-24 16:22:31 -0400
commit537b7695c26b9ad83ccc13b68c78a2fb27545d7e (patch)
treea801d360354343b92600df3e3eb255ff87ab8487 /libdimension/compiler-internal.h
parent77237a2e22acfc3f8a028cd1a4d63b602cbbf45e (diff)
downloaddimension-537b7695c26b9ad83ccc13b68c78a2fb27545d7e.tar.xz
Fix some warnings found by clang.
Diffstat (limited to 'libdimension/compiler-internal.h')
-rw-r--r--libdimension/compiler-internal.h45
1 files changed, 42 insertions, 3 deletions
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 <stdbool.h>
+#include <stdalign.h>
+/**
+ * @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