Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | From 230930b3bc3e431b819eb45420cb42475d83ca93 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?utf8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de> |
| 3 | Date: Wed, 1 Feb 2017 10:44:36 +0100 |
| 4 | Subject: [PATCH] Update intprops.h for gcc-7 compatibility |
| 5 | |
| 6 | --- |
| 7 | Upstream-Status: Backport |
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 9 | |
| 10 | gl/intprops.h | 65 ++++++++++++++++++++++++++++++-------------------- |
| 11 | lib/gltests/intprops.h | 65 ++++++++++++++++++++++++++++++-------------------- |
| 12 | 2 files changed, 78 insertions(+), 52 deletions(-) |
| 13 | |
| 14 | diff --git a/gl/intprops.h b/gl/intprops.h |
| 15 | index e1fce5c..eb06b69 100644 |
| 16 | --- a/gl/intprops.h |
| 17 | +++ b/gl/intprops.h |
| 18 | @@ -1,18 +1,18 @@ |
| 19 | /* intprops.h -- properties of integer types |
| 20 | |
| 21 | - Copyright (C) 2001-2016 Free Software Foundation, Inc. |
| 22 | + Copyright (C) 2001-2017 Free Software Foundation, Inc. |
| 23 | |
| 24 | This program is free software: you can redistribute it and/or modify it |
| 25 | - under the terms of the GNU General Public License as published |
| 26 | - by the Free Software Foundation; either version 3 of the License, or |
| 27 | + under the terms of the GNU Lesser General Public License as published |
| 28 | + by the Free Software Foundation; either version 2.1 of the License, or |
| 29 | (at your option) any later version. |
| 30 | |
| 31 | This program is distributed in the hope that it will be useful, |
| 32 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 | - GNU General Public License for more details. |
| 35 | + GNU Lesser General Public License for more details. |
| 36 | |
| 37 | - You should have received a copy of the GNU General Public License |
| 38 | + You should have received a copy of the GNU Lesser General Public License |
| 39 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 40 | |
| 41 | /* Written by Paul Eggert. */ |
| 42 | @@ -47,12 +47,16 @@ |
| 43 | |
| 44 | /* Minimum and maximum values for integer types and expressions. */ |
| 45 | |
| 46 | +/* The width in bits of the integer type or expression T. |
| 47 | + Padding bits are not supported; this is checked at compile-time below. */ |
| 48 | +#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) |
| 49 | + |
| 50 | /* The maximum and minimum values for the integer type T. */ |
| 51 | #define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t)) |
| 52 | #define TYPE_MAXIMUM(t) \ |
| 53 | ((t) (! TYPE_SIGNED (t) \ |
| 54 | ? (t) -1 \ |
| 55 | - : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) |
| 56 | + : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) |
| 57 | |
| 58 | /* The maximum and minimum values for the type of the expression E, |
| 59 | after integer promotion. E should not have side effects. */ |
| 60 | @@ -65,7 +69,13 @@ |
| 61 | ? _GL_SIGNED_INT_MAXIMUM (e) \ |
| 62 | : _GL_INT_NEGATE_CONVERT (e, 1)) |
| 63 | #define _GL_SIGNED_INT_MAXIMUM(e) \ |
| 64 | - (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) |
| 65 | + (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) |
| 66 | + |
| 67 | +/* Work around OpenVMS incompatibility with C99. */ |
| 68 | +#if !defined LLONG_MAX && defined __INT64_MAX |
| 69 | +# define LLONG_MAX __INT64_MAX |
| 70 | +# define LLONG_MIN __INT64_MIN |
| 71 | +#endif |
| 72 | |
| 73 | /* This include file assumes that signed types are two's complement without |
| 74 | padding bits; the above macros have undefined behavior otherwise. |
| 75 | @@ -84,10 +94,15 @@ verify (TYPE_MAXIMUM (long int) == LONG_MAX); |
| 76 | verify (TYPE_MINIMUM (long long int) == LLONG_MIN); |
| 77 | verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 78 | #endif |
| 79 | +/* Similarly, sanity-check one ISO/IEC TS 18661-1:2014 macro if defined. */ |
| 80 | +#ifdef UINT_WIDTH |
| 81 | +verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); |
| 82 | +#endif |
| 83 | |
| 84 | /* Does the __typeof__ keyword work? This could be done by |
| 85 | 'configure', but for now it's easier to do it by hand. */ |
| 86 | -#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ |
| 87 | +#if (2 <= __GNUC__ \ |
| 88 | + || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ |
| 89 | || (0x5110 <= __SUNPRO_C && !__STDC__)) |
| 90 | # define _GL_HAVE___TYPEOF__ 1 |
| 91 | #else |
| 92 | @@ -116,8 +131,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 93 | signed, this macro may overestimate the true bound by one byte when |
| 94 | applied to unsigned types of size 2, 4, 16, ... bytes. */ |
| 95 | #define INT_STRLEN_BOUND(t) \ |
| 96 | - (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ |
| 97 | - - _GL_SIGNED_TYPE_OR_EXPR (t)) \ |
| 98 | + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \ |
| 99 | + _GL_SIGNED_TYPE_OR_EXPR (t)) |
| 100 | |
| 101 | /* Bound on buffer size needed to represent an integer type or expression T, |
| 102 | @@ -222,20 +236,23 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 103 | ? (a) < (min) >> (b) \ |
| 104 | : (max) >> (b) < (a)) |
| 105 | |
| 106 | -/* True if __builtin_add_overflow (A, B, P) works when P is null. */ |
| 107 | -#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__) |
| 108 | +/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */ |
| 109 | +#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__) |
| 110 | + |
| 111 | +/* True if __builtin_add_overflow_p (A, B, C) works. */ |
| 112 | +#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) |
| 113 | |
| 114 | /* The _GL*_OVERFLOW macros have the same restrictions as the |
| 115 | *_RANGE_OVERFLOW macros, except that they do not assume that operands |
| 116 | (e.g., A and B) have the same type as MIN and MAX. Instead, they assume |
| 117 | that the result (e.g., A + B) has that type. */ |
| 118 | -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL |
| 119 | -# define _GL_ADD_OVERFLOW(a, b, min, max) |
| 120 | - __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0) |
| 121 | -# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) |
| 122 | - __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0) |
| 123 | -# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) |
| 124 | - __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0) |
| 125 | +#if _GL_HAS_BUILTIN_OVERFLOW_P |
| 126 | +# define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 127 | + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) |
| 128 | +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ |
| 129 | + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) |
| 130 | +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ |
| 131 | + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) |
| 132 | #else |
| 133 | # define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 134 | ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ |
| 135 | @@ -315,7 +332,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 136 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) |
| 137 | #define INT_SUBTRACT_OVERFLOW(a, b) \ |
| 138 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) |
| 139 | -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL |
| 140 | +#if _GL_HAS_BUILTIN_OVERFLOW_P |
| 141 | # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) |
| 142 | #else |
| 143 | # define INT_NEGATE_OVERFLOW(a) \ |
| 144 | @@ -349,10 +366,6 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 145 | #define INT_MULTIPLY_WRAPV(a, b, r) \ |
| 146 | _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) |
| 147 | |
| 148 | -#ifndef __has_builtin |
| 149 | -# define __has_builtin(x) 0 |
| 150 | -#endif |
| 151 | - |
| 152 | /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: |
| 153 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 |
| 154 | https://llvm.org/bugs/show_bug.cgi?id=25390 |
| 155 | @@ -369,7 +382,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 156 | the operation. BUILTIN is the builtin operation, and OVERFLOW the |
| 157 | overflow predicate. Return 1 if the result overflows. See above |
| 158 | for restrictions. */ |
| 159 | -#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow) |
| 160 | +#if _GL_HAS_BUILTIN_OVERFLOW |
| 161 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) |
| 162 | #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS |
| 163 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ |
| 164 | @@ -412,7 +425,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 165 | # else |
| 166 | # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ |
| 167 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ |
| 168 | - long int, LONG_MIN, LONG_MAX)) |
| 169 | + long int, LONG_MIN, LONG_MAX) |
| 170 | # endif |
| 171 | #endif |
| 172 | |
| 173 | diff --git a/lib/gltests/intprops.h b/lib/gltests/intprops.h |
| 174 | index e1fce5c..eb06b69 100644 |
| 175 | --- a/lib/gltests/intprops.h |
| 176 | +++ b/lib/gltests/intprops.h |
| 177 | @@ -1,18 +1,18 @@ |
| 178 | /* intprops.h -- properties of integer types |
| 179 | |
| 180 | - Copyright (C) 2001-2016 Free Software Foundation, Inc. |
| 181 | + Copyright (C) 2001-2017 Free Software Foundation, Inc. |
| 182 | |
| 183 | This program is free software: you can redistribute it and/or modify it |
| 184 | - under the terms of the GNU General Public License as published |
| 185 | - by the Free Software Foundation; either version 3 of the License, or |
| 186 | + under the terms of the GNU Lesser General Public License as published |
| 187 | + by the Free Software Foundation; either version 2.1 of the License, or |
| 188 | (at your option) any later version. |
| 189 | |
| 190 | This program is distributed in the hope that it will be useful, |
| 191 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 192 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 193 | - GNU General Public License for more details. |
| 194 | + GNU Lesser General Public License for more details. |
| 195 | |
| 196 | - You should have received a copy of the GNU General Public License |
| 197 | + You should have received a copy of the GNU Lesser General Public License |
| 198 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 199 | |
| 200 | /* Written by Paul Eggert. */ |
| 201 | @@ -47,12 +47,16 @@ |
| 202 | |
| 203 | /* Minimum and maximum values for integer types and expressions. */ |
| 204 | |
| 205 | +/* The width in bits of the integer type or expression T. |
| 206 | + Padding bits are not supported; this is checked at compile-time below. */ |
| 207 | +#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) |
| 208 | + |
| 209 | /* The maximum and minimum values for the integer type T. */ |
| 210 | #define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t)) |
| 211 | #define TYPE_MAXIMUM(t) \ |
| 212 | ((t) (! TYPE_SIGNED (t) \ |
| 213 | ? (t) -1 \ |
| 214 | - : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) |
| 215 | + : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) |
| 216 | |
| 217 | /* The maximum and minimum values for the type of the expression E, |
| 218 | after integer promotion. E should not have side effects. */ |
| 219 | @@ -65,7 +69,13 @@ |
| 220 | ? _GL_SIGNED_INT_MAXIMUM (e) \ |
| 221 | : _GL_INT_NEGATE_CONVERT (e, 1)) |
| 222 | #define _GL_SIGNED_INT_MAXIMUM(e) \ |
| 223 | - (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) |
| 224 | + (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) |
| 225 | + |
| 226 | +/* Work around OpenVMS incompatibility with C99. */ |
| 227 | +#if !defined LLONG_MAX && defined __INT64_MAX |
| 228 | +# define LLONG_MAX __INT64_MAX |
| 229 | +# define LLONG_MIN __INT64_MIN |
| 230 | +#endif |
| 231 | |
| 232 | /* This include file assumes that signed types are two's complement without |
| 233 | padding bits; the above macros have undefined behavior otherwise. |
| 234 | @@ -84,10 +94,15 @@ verify (TYPE_MAXIMUM (long int) == LONG_MAX); |
| 235 | verify (TYPE_MINIMUM (long long int) == LLONG_MIN); |
| 236 | verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 237 | #endif |
| 238 | +/* Similarly, sanity-check one ISO/IEC TS 18661-1:2014 macro if defined. */ |
| 239 | +#ifdef UINT_WIDTH |
| 240 | +verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); |
| 241 | +#endif |
| 242 | |
| 243 | /* Does the __typeof__ keyword work? This could be done by |
| 244 | 'configure', but for now it's easier to do it by hand. */ |
| 245 | -#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ |
| 246 | +#if (2 <= __GNUC__ \ |
| 247 | + || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ |
| 248 | || (0x5110 <= __SUNPRO_C && !__STDC__)) |
| 249 | # define _GL_HAVE___TYPEOF__ 1 |
| 250 | #else |
| 251 | @@ -116,8 +131,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 252 | signed, this macro may overestimate the true bound by one byte when |
| 253 | applied to unsigned types of size 2, 4, 16, ... bytes. */ |
| 254 | #define INT_STRLEN_BOUND(t) \ |
| 255 | - (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ |
| 256 | - - _GL_SIGNED_TYPE_OR_EXPR (t)) \ |
| 257 | + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \ |
| 258 | + _GL_SIGNED_TYPE_OR_EXPR (t)) |
| 259 | |
| 260 | /* Bound on buffer size needed to represent an integer type or expression T, |
| 261 | @@ -222,20 +236,23 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 262 | ? (a) < (min) >> (b) \ |
| 263 | : (max) >> (b) < (a)) |
| 264 | |
| 265 | -/* True if __builtin_add_overflow (A, B, P) works when P is null. */ |
| 266 | -#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__) |
| 267 | +/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */ |
| 268 | +#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__) |
| 269 | + |
| 270 | +/* True if __builtin_add_overflow_p (A, B, C) works. */ |
| 271 | +#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) |
| 272 | |
| 273 | /* The _GL*_OVERFLOW macros have the same restrictions as the |
| 274 | *_RANGE_OVERFLOW macros, except that they do not assume that operands |
| 275 | (e.g., A and B) have the same type as MIN and MAX. Instead, they assume |
| 276 | that the result (e.g., A + B) has that type. */ |
| 277 | -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL |
| 278 | -# define _GL_ADD_OVERFLOW(a, b, min, max) |
| 279 | - __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0) |
| 280 | -# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) |
| 281 | - __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0) |
| 282 | -# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) |
| 283 | - __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0) |
| 284 | +#if _GL_HAS_BUILTIN_OVERFLOW_P |
| 285 | +# define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 286 | + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) |
| 287 | +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ |
| 288 | + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) |
| 289 | +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ |
| 290 | + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) |
| 291 | #else |
| 292 | # define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 293 | ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ |
| 294 | @@ -315,7 +332,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 295 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) |
| 296 | #define INT_SUBTRACT_OVERFLOW(a, b) \ |
| 297 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) |
| 298 | -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL |
| 299 | +#if _GL_HAS_BUILTIN_OVERFLOW_P |
| 300 | # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) |
| 301 | #else |
| 302 | # define INT_NEGATE_OVERFLOW(a) \ |
| 303 | @@ -349,10 +366,6 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 304 | #define INT_MULTIPLY_WRAPV(a, b, r) \ |
| 305 | _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) |
| 306 | |
| 307 | -#ifndef __has_builtin |
| 308 | -# define __has_builtin(x) 0 |
| 309 | -#endif |
| 310 | - |
| 311 | /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: |
| 312 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 |
| 313 | https://llvm.org/bugs/show_bug.cgi?id=25390 |
| 314 | @@ -369,7 +382,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 315 | the operation. BUILTIN is the builtin operation, and OVERFLOW the |
| 316 | overflow predicate. Return 1 if the result overflows. See above |
| 317 | for restrictions. */ |
| 318 | -#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow) |
| 319 | +#if _GL_HAS_BUILTIN_OVERFLOW |
| 320 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) |
| 321 | #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS |
| 322 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ |
| 323 | @@ -412,7 +425,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); |
| 324 | # else |
| 325 | # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ |
| 326 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ |
| 327 | - long int, LONG_MIN, LONG_MAX)) |
| 328 | + long int, LONG_MIN, LONG_MAX) |
| 329 | # endif |
| 330 | #endif |
| 331 | |
| 332 | -- |
| 333 | 1.9.1 |
| 334 | |