]> Savannah Git Hosting - gnulib.git/commitdiff
verify: avoid __built_assume on Clang
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Aug 2020 21:47:45 +0000 (14:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Aug 2020 21:58:05 +0000 (14:58 -0700)
* lib/verify.h (assume): Do not use Clang’s __builtin_assume, as
Clang 9 incorrectly diagnoses arguments as having side effects
even when they do not.  I guess Clang 9 considers any function
call as if it had a side effect here.

ChangeLog
lib/verify.h

index ba521c265d57a4472b00e43d47faf266c0e21fac..9ba0cda9276633c7cbbf8938fbfc39482dd01319 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+       verify: avoid __built_assume on Clang
+       * lib/verify.h (assume): Do not use Clang’s __builtin_assume, as
+       Clang 9 incorrectly diagnoses arguments as having side effects
+       even when they do not.  I guess Clang 9 considers any function
+       call as if it had a side effect here.
+
        libc-config: avoid Clang’s __diagnose_if__
        * lib/cdefs.h (__warndecl, __warnattr, __errordecl):
        For now, do not use __diagnose_if__ here, as this fails
index 0ba8d579071dbda845f309e218e6325670484f25..d485a0283a972c4f247580064f07344044bea1bb 100644 (file)
@@ -246,13 +246,6 @@ 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
@@ -312,11 +305,14 @@ template <int w>
 
    Although assuming R can help a compiler generate better code or
    diagnostics, performance can suffer if R uses hard-to-optimize
-   features such as function calls not inlined by the compiler.  */
+   features such as function calls not inlined by the compiler.
+
+   Avoid Clang’s __builtin_assume, as clang 9.0.1 -Wassume can
+   generate a bogus diagnostic "the argument to '__builtin_assume' has
+   side effects that will be discarded" even when the argument has no
+   side effects.  */
 
-#if _GL_HAS_BUILTIN_ASSUME
-# define assume(R) __builtin_assume (R)
-#elif _GL_HAS_BUILTIN_UNREACHABLE
+#if _GL_HAS_BUILTIN_UNREACHABLE
 # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER
 # define assume(R) __assume (R)