From 7928f62273e43bf4e22c664916fb1486329bae48 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Wed, 12 Aug 2015 16:38:39 -0700 Subject: [PATCH] Check whether gcc version supports __builtin_unreachable(). --- include/jemalloc/internal/util.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/jemalloc/internal/util.h b/include/jemalloc/internal/util.h index c977aeaa..c23e4ac6 100644 --- a/include/jemalloc/internal/util.h +++ b/include/jemalloc/internal/util.h @@ -57,10 +57,21 @@ # define JEMALLOC_CC_SILENCE_INIT(v) #endif +#define JEMALLOC_GNUC_PREREQ(major, minor) \ + (!defined(__clang__) && \ + (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))) +#define JEMALLOC_CLANG_HAS_BUILTIN(builtin) \ + (defined(__clang__) && __has_builtin(builtin)) + #ifdef __GNUC__ # define likely(x) __builtin_expect(!!(x), 1) # define unlikely(x) __builtin_expect(!!(x), 0) +# if JEMALLOC_GNUC_PREREQ(4, 6) || \ + JEMALLOC_CLANG_HAS_BUILTIN(__builtin_unreachable) # define unreachable() __builtin_unreachable() +# else +# define unreachable() +# endif #else # define likely(x) !!(x) # define unlikely(x) !!(x)