aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorElliot Ronaghan <ronawho@gmail.com>2016-06-17 13:28:39 -0700
committerJason Evans <jasone@canonware.com>2016-09-26 10:44:37 -0700
commitd1207f0d371eade218f7572743b5eddedc7fff94 (patch)
tree953c2a018738b1837ad492f24dda9e59008845d3 /include
parenta6a8e40f7d24ee9f4f6abf1c03e1e0d7e3763084 (diff)
downloadjemalloc-d1207f0d371eade218f7572743b5eddedc7fff94.tar.gz
Check for __builtin_unreachable at configure time
Add a configure check for __builtin_unreachable instead of basing its availability on the __GNUC__ version. On OS X using gcc (a real gcc, not the bundled version that's just a gcc front-end) leads to a linker assertion: https://github.com/jemalloc/jemalloc/issues/266 It turns out that this is caused by a gcc bug resulting from the use of __builtin_unreachable(): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57438 To work around this bug, check that __builtin_unreachable() actually works at configure time, and if it doesn't use abort() instead. The check is based on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57438#c21. With this `make check` passes with a homebrew installed gcc-5 and gcc-6.
Diffstat (limited to 'include')
-rw-r--r--include/jemalloc/internal/jemalloc_internal_defs.h.in6
-rw-r--r--include/jemalloc/internal/util.h22
2 files changed, 12 insertions, 16 deletions
diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in
index 7de0cf7..22396b7 100644
--- a/include/jemalloc/internal/jemalloc_internal_defs.h.in
+++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in
@@ -189,6 +189,12 @@
#undef JEMALLOC_TLS
/*
+ * Used to mark unreachable code to quiet "end of non-void" compiler warnings.
+ * Don't use this directly; instead use unreachable() from util.h
+ */
+#undef JEMALLOC_INTERNAL_UNREACHABLE
+
+/*
* ffs*() functions to use for bitmapping. Don't use these directly; instead,
* use ffs_*() from util.h.
*/
diff --git a/include/jemalloc/internal/util.h b/include/jemalloc/internal/util.h
index a0c2203..aee00d6 100644
--- a/include/jemalloc/internal/util.h
+++ b/include/jemalloc/internal/util.h
@@ -61,30 +61,20 @@
# define JEMALLOC_CC_SILENCE_INIT(v)
#endif
-#define JEMALLOC_GNUC_PREREQ(major, minor) \
- (!defined(__clang__) && \
- (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
-#ifndef __has_builtin
-# define __has_builtin(builtin) (0)
-#endif
-#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() abort()
-# endif
#else
# define likely(x) !!(x)
# define unlikely(x) !!(x)
-# define unreachable() abort()
#endif
+#if !defined(JEMALLOC_INTERNAL_UNREACHABLE)
+# error JEMALLOC_INTERNAL_UNREACHABLE should have been defined by configure
+#endif
+
+#define unreachable() JEMALLOC_INTERNAL_UNREACHABLE()
+
#include "jemalloc/internal/assert.h"
/* Use to assert a particular configuration, e.g., cassert(config_debug). */