]> Savannah Git Hosting - gnulib.git/commitdiff
Use __builtin_assume with clang.
authorBruno Haible <bruno@clisp.org>
Fri, 7 Aug 2020 00:12:09 +0000 (02:12 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 7 Aug 2020 00:12:09 +0000 (02:12 +0200)
* lib/verify.h (_GL_HAS_BUILTIN_ASSUME): New macro.
(assume): Use __builtin_assume when available.

ChangeLog
lib/verify.h

index d78accc3e683ce9ce01b4e90e7aaefa205d62232..19aff68253d2382c0bc724f73ec579d43d5cf846 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-06  Bruno Haible  <bruno@clisp.org>
+
+       Use __builtin_assume with clang.
+       * lib/verify.h (_GL_HAS_BUILTIN_ASSUME): New macro.
+       (assume): Use __builtin_assume when available.
+
 2020-08-06  Paul Eggert  <eggert@cs.ucla.edu>
 
        libgmp: add <gmp/gmp.h> support
index f1097612704aa5d0a43b966984943c5a3d1c309e..58172f3cb7f6262d1622871aa69671307c93aeef 100644 (file)
@@ -233,6 +233,13 @@ template <int w>
 
 /* @assert.h omit start@  */
 
+#if defined __has_builtin
+/* <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions> */
+# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume)
+#else
+# define _GL_HAS_BUILTIN_ASSUME 0
+#endif
+
 #if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
 # define _GL_HAS_BUILTIN_TRAP 1
 #elif defined __has_builtin
@@ -294,7 +301,9 @@ template <int w>
    diagnostics, performance can suffer if R uses hard-to-optimize
    features such as function calls not inlined by the compiler.  */
 
-#if _GL_HAS_BUILTIN_UNREACHABLE
+#if _GL_HAS_BUILTIN_ASSUME
+# define assume(R) __builtin_assume (R)
+#elif _GL_HAS_BUILTIN_UNREACHABLE
 # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER
 # define assume(R) __assume (R)