at 18.09-beta 12 kB view raw
1Description: Update to latest intprops.h from gnulib, fixes FTBFS with gcc 7 2Author: Adrian Bunk <bunk@debian.org> 3Bug-Debian: https://bugs.debian.org/853649 4 5--- rush-1.8+dfsg.orig/gnu/intprops.h 6+++ rush-1.8+dfsg/gnu/intprops.h 7@@ -1,20 +1,18 @@ 8-/* -*- buffer-read-only: t -*- vi: set ro: */ 9-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 10 /* intprops.h -- properties of integer types 11 12- Copyright (C) 2001-2016 Free Software Foundation, Inc. 13+ Copyright (C) 2001-2017 Free Software Foundation, Inc. 14 15 This program is free software: you can redistribute it and/or modify it 16- under the terms of the GNU General Public License as published 17- by the Free Software Foundation; either version 3 of the License, or 18+ under the terms of the GNU Lesser General Public License as published 19+ by the Free Software Foundation; either version 2.1 of the License, or 20 (at your option) any later version. 21 22 This program is distributed in the hope that it will be useful, 23 but WITHOUT ANY WARRANTY; without even the implied warranty of 24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25- GNU General Public License for more details. 26+ GNU Lesser General Public License for more details. 27 28- You should have received a copy of the GNU General Public License 29+ You should have received a copy of the GNU Lesser General Public License 30 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 31 32 /* Written by Paul Eggert. */ 33@@ -23,7 +21,6 @@ 34 #define _GL_INTPROPS_H 35 36 #include <limits.h> 37-#include <verify.h> 38 39 /* Return a value with the common real type of E and V and the value of V. */ 40 #define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) 41@@ -49,12 +46,16 @@ 42 43 /* Minimum and maximum values for integer types and expressions. */ 44 45+/* The width in bits of the integer type or expression T. 46+ Padding bits are not supported; this is checked at compile-time below. */ 47+#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) 48+ 49 /* The maximum and minimum values for the integer type T. */ 50 #define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t)) 51 #define TYPE_MAXIMUM(t) \ 52 ((t) (! TYPE_SIGNED (t) \ 53 ? (t) -1 \ 54- : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) 55+ : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) 56 57 /* The maximum and minimum values for the type of the expression E, 58 after integer promotion. E should not have side effects. */ 59@@ -67,29 +68,23 @@ 60 ? _GL_SIGNED_INT_MAXIMUM (e) \ 61 : _GL_INT_NEGATE_CONVERT (e, 1)) 62 #define _GL_SIGNED_INT_MAXIMUM(e) \ 63- (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) 64+ (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) 65+ 66+/* Work around OpenVMS incompatibility with C99. */ 67+#if !defined LLONG_MAX && defined __INT64_MAX 68+# define LLONG_MAX __INT64_MAX 69+# define LLONG_MIN __INT64_MIN 70+#endif 71 72 /* This include file assumes that signed types are two's complement without 73 padding bits; the above macros have undefined behavior otherwise. 74 If this is a problem for you, please let us know how to fix it for your host. 75- As a sanity check, test the assumption for some signed types that 76- <limits.h> bounds. */ 77-verify (TYPE_MINIMUM (signed char) == SCHAR_MIN); 78-verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX); 79-verify (TYPE_MINIMUM (short int) == SHRT_MIN); 80-verify (TYPE_MAXIMUM (short int) == SHRT_MAX); 81-verify (TYPE_MINIMUM (int) == INT_MIN); 82-verify (TYPE_MAXIMUM (int) == INT_MAX); 83-verify (TYPE_MINIMUM (long int) == LONG_MIN); 84-verify (TYPE_MAXIMUM (long int) == LONG_MAX); 85-#ifdef LLONG_MAX 86-verify (TYPE_MINIMUM (long long int) == LLONG_MIN); 87-verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); 88-#endif 89+ This assumption is tested by the intprops-tests module. */ 90 91 /* Does the __typeof__ keyword work? This could be done by 92 'configure', but for now it's easier to do it by hand. */ 93-#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ 94+#if (2 <= __GNUC__ \ 95+ || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ 96 || (0x5110 <= __SUNPRO_C && !__STDC__)) 97 # define _GL_HAVE___TYPEOF__ 1 98 #else 99@@ -118,8 +113,7 @@ verify (TYPE_MAXIMUM (long long int) == 100 signed, this macro may overestimate the true bound by one byte when 101 applied to unsigned types of size 2, 4, 16, ... bytes. */ 102 #define INT_STRLEN_BOUND(t) \ 103- (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ 104- - _GL_SIGNED_TYPE_OR_EXPR (t)) \ 105+ (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \ 106 + _GL_SIGNED_TYPE_OR_EXPR (t)) 107 108 /* Bound on buffer size needed to represent an integer type or expression T, 109@@ -224,20 +218,27 @@ verify (TYPE_MAXIMUM (long long int) == 110 ? (a) < (min) >> (b) \ 111 : (max) >> (b) < (a)) 112 113-/* True if __builtin_add_overflow (A, B, P) works when P is null. */ 114-#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__) 115+/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */ 116+#if 5 <= __GNUC__ && !defined __ICC 117+# define _GL_HAS_BUILTIN_OVERFLOW 1 118+#else 119+# define _GL_HAS_BUILTIN_OVERFLOW 0 120+#endif 121+ 122+/* True if __builtin_add_overflow_p (A, B, C) works. */ 123+#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) 124 125 /* The _GL*_OVERFLOW macros have the same restrictions as the 126 *_RANGE_OVERFLOW macros, except that they do not assume that operands 127 (e.g., A and B) have the same type as MIN and MAX. Instead, they assume 128 that the result (e.g., A + B) has that type. */ 129-#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL 130-# define _GL_ADD_OVERFLOW(a, b, min, max) 131- __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0) 132-# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) 133- __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0) 134-# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) 135- __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0) 136+#if _GL_HAS_BUILTIN_OVERFLOW_P 137+# define _GL_ADD_OVERFLOW(a, b, min, max) \ 138+ __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) 139+# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ 140+ __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) 141+# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ 142+ __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) 143 #else 144 # define _GL_ADD_OVERFLOW(a, b, min, max) \ 145 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ 146@@ -317,7 +318,7 @@ verify (TYPE_MAXIMUM (long long int) == 147 _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) 148 #define INT_SUBTRACT_OVERFLOW(a, b) \ 149 _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) 150-#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL 151+#if _GL_HAS_BUILTIN_OVERFLOW_P 152 # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) 153 #else 154 # define INT_NEGATE_OVERFLOW(a) \ 155@@ -351,10 +352,6 @@ verify (TYPE_MAXIMUM (long long int) == 156 #define INT_MULTIPLY_WRAPV(a, b, r) \ 157 _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) 158 159-#ifndef __has_builtin 160-# define __has_builtin(x) 0 161-#endif 162- 163 /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: 164 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 165 https://llvm.org/bugs/show_bug.cgi?id=25390 166@@ -371,17 +368,17 @@ verify (TYPE_MAXIMUM (long long int) == 167 the operation. BUILTIN is the builtin operation, and OVERFLOW the 168 overflow predicate. Return 1 if the result overflows. See above 169 for restrictions. */ 170-#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow) 171+#if _GL_HAS_BUILTIN_OVERFLOW 172 # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) 173 #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS 174 # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ 175 (_Generic \ 176 (*(r), \ 177 signed char: \ 178- _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \ 179+ _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 180 signed char, SCHAR_MIN, SCHAR_MAX), \ 181 short int: \ 182- _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \ 183+ _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 184 short int, SHRT_MIN, SHRT_MAX), \ 185 int: \ 186 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 187@@ -395,10 +392,10 @@ verify (TYPE_MAXIMUM (long long int) == 188 #else 189 # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ 190 (sizeof *(r) == sizeof (signed char) \ 191- ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \ 192+ ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 193 signed char, SCHAR_MIN, SCHAR_MAX) \ 194 : sizeof *(r) == sizeof (short int) \ 195- ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \ 196+ ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 197 short int, SHRT_MIN, SHRT_MAX) \ 198 : sizeof *(r) == sizeof (int) \ 199 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ 200@@ -414,15 +411,14 @@ verify (TYPE_MAXIMUM (long long int) == 201 # else 202 # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ 203 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ 204- long int, LONG_MIN, LONG_MAX)) 205+ long int, LONG_MIN, LONG_MAX) 206 # endif 207 #endif 208 209 /* Store the low-order bits of A <op> B into *R, where the operation 210 is given by OP. Use the unsigned type UT for calculation to avoid 211- overflow problems. *R's type is T, with extremal values TMIN and 212- TMAX. T must be a signed integer type. Return 1 if the result 213- overflows. */ 214+ overflow problems. *R's type is T, with extrema TMIN and TMAX. 215+ T must be a signed integer type. Return 1 if the result overflows. */ 216 #define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ 217 (sizeof ((a) op (b)) < sizeof (t) \ 218 ? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \ 219@@ -431,17 +427,27 @@ verify (TYPE_MAXIMUM (long long int) == 220 ((overflow (a, b) \ 221 || (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \ 222 || (tmax) < ((a) op (b))) \ 223- ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 1) \ 224- : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 0)) 225+ ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \ 226+ : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0)) 227+ 228+/* Return the low-order bits of A <op> B, where the operation is given 229+ by OP. Use the unsigned type UT for calculation to avoid undefined 230+ behavior on signed integer overflow, and convert the result to type T. 231+ UT is at least as wide as T and is no narrower than unsigned int, 232+ T is two's complement, and there is no padding or trap representations. 233+ Assume that converting UT to T yields the low-order bits, as is 234+ done in all known two's-complement C compilers. E.g., see: 235+ https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html 236+ 237+ According to the C standard, converting UT to T yields an 238+ implementation-defined result or signal for values outside T's 239+ range. However, code that works around this theoretical problem 240+ runs afoul of a compiler bug in Oracle Studio 12.3 x86. See: 241+ http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html 242+ As the compiler bug is real, don't try to work around the 243+ theoretical problem. */ 244 245-/* Return A <op> B, where the operation is given by OP. Use the 246- unsigned type UT for calculation to avoid overflow problems. 247- Convert the result to type T without overflow by subtracting TMIN 248- from large values before converting, and adding it afterwards. 249- Compilers can optimize all the operations except OP. */ 250-#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t, tmin, tmax) \ 251- (((ut) (a) op (ut) (b)) <= (tmax) \ 252- ? (t) ((ut) (a) op (ut) (b)) \ 253- : ((t) (((ut) (a) op (ut) (b)) - (tmin)) + (tmin))) 254+#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \ 255+ ((t) ((ut) (a) op (ut) (b))) 256 257 #endif /* _GL_INTPROPS_H */