From 77de583eb1a7577a0e85cd4023655d5ee542a205 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 29 Aug 2016 12:03:51 -0700 Subject: [PATCH] intprops.h: port recent changes to GCC 6.2.0 * lib/intprops.h (__has_builtin): Move earlier. (_GL_HAS_BUILTIN_OVERFLOW): Rename from _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL and don't worry about whether the last argument can be null. All uses changed. (_GL_HAS_BUILTIN_OVERFLOW_P): Also test __has_builtin. (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW, _GL_MULTIPLY_OVERFLOW): Don't try to use 3rd arg null, as this doesn't work on GCC 6.2.0 and it's not clear which GCC versions it works for. (_GL_INT_OP_WRAPV): Use _GL_HAS_BUILTIN_OVERFLOW instead of its definiens. --- ChangeLog | 12 ++++++++++++ lib/intprops.h | 27 +++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70012b7..cc437f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2016-08-29 Paul Eggert + intprops.h: port recent changes to GCC 6.2.0 + * lib/intprops.h (__has_builtin): Move earlier. + (_GL_HAS_BUILTIN_OVERFLOW): Rename from + _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL and don't worry about whether + the last argument can be null. All uses changed. + (_GL_HAS_BUILTIN_OVERFLOW_P): Also test __has_builtin. + (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW, _GL_MULTIPLY_OVERFLOW): + Don't try to use 3rd arg null, as this doesn't work on GCC 6.2.0 + and it's not clear which GCC versions it works for. + (_GL_INT_OP_WRAPV): Use _GL_HAS_BUILTIN_OVERFLOW instead of + its definiens. + intprops.h: use __typeof__ with GCC 7 * lib/intprops.h (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW) (_GL_MULTIPLY_OVERFLOW): Use __typeof__ as in the GCC manual. diff --git a/lib/intprops.h b/lib/intprops.h index 32ee71a..744e64b 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -23,6 +23,10 @@ #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)) @@ -228,11 +232,13 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); ? (a) < (min) >> (b) \ : (max) >> (b) < (a)) -/* True if __builtin_add_overflow (A, B, P) works when P is null. */ -#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (6 == __GNUC__) +/* 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)) /* True if __builtin_add_overflow_p (A, B, C) works. */ -#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) +#define _GL_HAS_BUILTIN_OVERFLOW_P \ + (7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p)) /* The _GL*_OVERFLOW macros have the same restrictions as the *_RANGE_OVERFLOW macros, except that they do not assume that operands @@ -245,13 +251,6 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) # define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) -#elif _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL -# define _GL_ADD_OVERFLOW(a, b, min, max) \ - __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0) -# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ - __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0) -# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ - __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0) #else # define _GL_ADD_OVERFLOW(a, b, min, max) \ ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ @@ -331,7 +330,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) #define INT_SUBTRACT_OVERFLOW(a, b) \ _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL +#if _GL_HAS_BUILTIN_OVERFLOW || _GL_HAS_BUILTIN_OVERFLOW_P # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) #else # define INT_NEGATE_OVERFLOW(a) \ @@ -365,10 +364,6 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); #define INT_MULTIPLY_WRAPV(a, b, r) \ _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) -#ifndef __has_builtin -# define __has_builtin(x) 0 -#endif - /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 https://llvm.org/bugs/show_bug.cgi?id=25390 @@ -385,7 +380,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); the operation. BUILTIN is the builtin operation, and OVERFLOW the overflow predicate. Return 1 if the result overflows. See above for restrictions. */ -#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow) +#if _GL_HAS_BUILTIN_OVERFLOW # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ -- 2.7.4