]> Savannah Git Hosting - gnulib.git/commitdiff
glob, intprops, xalloc: work around Clang bug
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jan 2017 21:36:57 +0000 (13:36 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jan 2017 21:38:05 +0000 (13:38 -0800)
Work around LLVM bug 16404, which is still not fixed.
https://llvm.org/bugs/show_bug.cgi?id=16404
Problem reported by Nelson H. F. Beebe.
* lib/glob.c, lib/intprops.h, lib/xalloc-oversized.h (__has_builtin):
Remove.
* lib/glob.c (size_add_wrapv):
* lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P):
* lib/xalloc-oversized.h (xalloc_oversized):
Do not use overflow builtins if Clang.

ChangeLog
lib/glob.c
lib/intprops.h
lib/xalloc-oversized.h

index d3dad042a741f9d25babe9e5470d4707341c14ba..73db88a71a85b7e0936b89035fc23dfdfaca282a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2017-01-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       glob, intprops, xalloc: work around Clang bug
+       Work around LLVM bug 16404, which is still not fixed.
+       https://llvm.org/bugs/show_bug.cgi?id=16404
+       Problem reported by Nelson H. F. Beebe.
+       * lib/glob.c, lib/intprops.h, lib/xalloc-oversized.h (__has_builtin):
+       Remove.
+       * lib/glob.c (size_add_wrapv):
+       * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P):
+       * lib/xalloc-oversized.h (xalloc_oversized):
+       Do not use overflow builtins if Clang.
+
        dfa: fix 'return' typo
        Problem reported by Nelson H. F. Beebe.
        * lib/dfa.c (merge): Fix typo that Sun compilers rejected.
index 622fbf68f7a4d84f27f75d7b7f63d5686c3c43ea..e91c34db65a2057a7fad363428f36c6f22018acc 100644 (file)
@@ -246,10 +246,6 @@ convert_dirent64 (const struct dirent64 *source)
     ((void) (buf), (void) (len), (void) (newlen), (void) (avar), (void *) 0)
 #endif
 
-#ifndef __has_builtin
-# define __has_builtin(x) 0
-#endif
-
 /* Set *R = A + B.  Return true if the answer is mathematically
    incorrect due to overflow; in this case, *R is the low order
    bits of the correct answer..  */
@@ -257,7 +253,7 @@ convert_dirent64 (const struct dirent64 *source)
 static bool
 size_add_wrapv (size_t a, size_t b, size_t *r)
 {
-#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow)
+#if 5 <= __GNUC__
   return __builtin_add_overflow (a, b, r);
 #else
   *r = a + b;
index 3b0c5d0dfdb4e0c2aacb9238eb5f01c943c0d567..eb06b6917e6b089ae163f6e121512d8f6ab6d6f3 100644 (file)
 #include <limits.h>
 #include <verify.h>
 
-#ifndef __has_builtin
-# define __has_builtin(x) 0
-#endif
-
 /* Return a value with the common real type of E and V and the value of V.  */
 #define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
 
@@ -241,12 +237,10 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
    : (max) >> (b) < (a))
 
 /* True if __builtin_add_overflow (A, B, P) works when P is non-null.  */
-#define _GL_HAS_BUILTIN_OVERFLOW \
-  (5 <= __GNUC__ || __has_builtin (__builtin_add_overflow))
+#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__)
 
 /* True if __builtin_add_overflow_p (A, B, C) works.  */
-#define _GL_HAS_BUILTIN_OVERFLOW_P \
-  (7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p))
+#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
 
 /* The _GL*_OVERFLOW macros have the same restrictions as the
    *_RANGE_OVERFLOW macros, except that they do not assume that operands
index 6b4e68b7c0e70ab2f32c26f9e0f65b4574bc8c84..ff0efc6ba40553ff6a94698cc505063061ccde04 100644 (file)
 #include <stddef.h>
 #include <stdint.h>
 
-/* Default for (non-Clang) compilers that lack __has_builtin.  */
-#ifndef __has_builtin
-# define __has_builtin(x) 0
-#endif
-
 /* True if N * S would overflow in a size_t calculation,
    or would generate a value larger than PTRDIFF_MAX.
    This expands to a constant expression if N and S are both constants.
@@ -46,13 +41,10 @@ typedef size_t __xalloc_count_type;
    positive and N must be nonnegative.  This is a macro, not a
    function, so that it works correctly even when SIZE_MAX < N.  */
 
-#if 7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p)
+#if 7 <= __GNUC__
 # define xalloc_oversized(n, s) \
    __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
-#elif ((5 <= __GNUC__ \
-        || (__has_builtin (__builtin_mul_overflow) \
-            && __has_builtin (__builtin_constant_p))) \
-       && !__STRICT_ANSI__)
+#elif 5 <= __GNUC__ && !__STRICT_ANSI__
 # define xalloc_oversized(n, s) \
    (__builtin_constant_p (n) && __builtin_constant_p (s) \
     ? __xalloc_oversized (n, s) \