aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-01-08 22:00:52 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-01-09 10:41:17 +0100
commitfc4ca5bdd8c5a2b37b6efe34a9b32a1bd75c57af (patch)
tree5d2a8d101f513807fac7f88a011ad88976141277 /src
parent596f020e904b2da2dac1bc080eb69f66deb998d7 (diff)
downloadrneovim-fc4ca5bdd8c5a2b37b6efe34a9b32a1bd75c57af.tar.gz
rneovim-fc4ca5bdd8c5a2b37b6efe34a9b32a1bd75c57af.tar.bz2
rneovim-fc4ca5bdd8c5a2b37b6efe34a9b32a1bd75c57af.zip
CMake: Feature-detect __builtin_{add,sub}_overflow
Diffstat (limited to 'src')
-rw-r--r--src/nvim/assert.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/assert.h b/src/nvim/assert.h
index 3f985475a7..29195a49dc 100644
--- a/src/nvim/assert.h
+++ b/src/nvim/assert.h
@@ -122,6 +122,7 @@
#endif
/// @def STRICT_ADD
+/// @brief Adds (a + b) and stores result in `c`. Aborts on overflow.
///
/// Requires GCC 5+ and Clang 3.8+
/// https://clang.llvm.org/docs/LanguageExtensions.html
@@ -132,8 +133,7 @@
///
/// @param MAX Maximum value of the narrowest type of operand.
/// Not used if compiler supports __builtin_add_overflow.
-#if (defined(__clang__) && __has_builtin(__builtin_add_overflow)) \
- || (__GNUC__ >= 5)
+#if HAVE_BUILTIN_ADD_OVERFLOW
# define STRICT_ADD(a, b, c, t) \
do { if (__builtin_add_overflow(a, b, c)) { abort(); } } while (0)
#else
@@ -141,8 +141,9 @@
do { *(c) = (t)(a + b); } while (0)
#endif
-#if (defined(__clang__) && __has_builtin(__builtin_sub_overflow)) \
- || (__GNUC__ >= 5)
+/// @def STRICT_SUB
+/// @brief Subtracts (a - b) and stores result in `c`. Aborts on overflow.
+#if HAVE_BUILTIN_ADD_OVERFLOW
# define STRICT_SUB(a, b, c, t) \
do { if (__builtin_sub_overflow(a, b, c)) { abort(); } } while (0)
#else