From: Paul Eggert Date: Fri, 6 Jan 2017 21:36:57 +0000 (-0800) Subject: glob, intprops, xalloc: work around Clang bug X-Git-Tag: v1.0~6407 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=04441fd8156978cfc51d6c203fd43c23b64f95df;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index d3dad042a7..73db88a71a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2017-01-06 Paul Eggert + 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. diff --git a/lib/glob.c b/lib/glob.c index 622fbf68f7..e91c34db65 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -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; diff --git a/lib/intprops.h b/lib/intprops.h index 3b0c5d0dfd..eb06b6917e 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -23,10 +23,6 @@ #include #include -#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 diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h index 6b4e68b7c0..ff0efc6ba4 100644 --- a/lib/xalloc-oversized.h +++ b/lib/xalloc-oversized.h @@ -21,11 +21,6 @@ #include #include -/* 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) \