diff options
| author | Paul Eggert | 2016-08-30 13:15:04 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-08-30 13:16:22 -0700 |
| commit | 6cf3ee3d5474a61d6615a6a21d9e7723f7ba9151 (patch) | |
| tree | d5cf44ee8f53d85a88fc9e8c355dfee252e9dfd8 /lib | |
| parent | 1145322a114bb7359fcfdbdce6ccb7d9d44c82ba (diff) | |
| download | emacs-6cf3ee3d5474a61d6615a6a21d9e7723f7ba9151.tar.gz emacs-6cf3ee3d5474a61d6615a6a21d9e7723f7ba9151.zip | |
Update from gnulib
This incorporates:
2016-08-30 intprops: tune INT_NEGATE_OVERFLOW for GCC 5 and 6
2016-08-29 xalloc-oversized.h: port change to GCC 6.2.0
2016-08-29 intprops.h: port recent changes to GCC 6.2.0
2016-08-29 intprops.h: use __typeof__ with GCC 7
2016-08-29 intprops.h, xalloc-oversized.h: work with gcc 7
2016-08-24 intprops: fix paren typo on old platforms
2016-08-24 intprops: port to OpenVMS
* lib/intprops.h, lib/xalloc-oversized.h: Copy from gnulib.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/intprops.h | 43 | ||||
| -rw-r--r-- | lib/xalloc-oversized.h | 12 |
2 files changed, 29 insertions, 26 deletions
diff --git a/lib/intprops.h b/lib/intprops.h index e1fce5c96a1..7e832bcdf1b 100644 --- a/lib/intprops.h +++ b/lib/intprops.h | |||
| @@ -23,6 +23,10 @@ | |||
| 23 | #include <limits.h> | 23 | #include <limits.h> |
| 24 | #include <verify.h> | 24 | #include <verify.h> |
| 25 | 25 | ||
| 26 | #ifndef __has_builtin | ||
| 27 | # define __has_builtin(x) 0 | ||
| 28 | #endif | ||
| 29 | |||
| 26 | /* Return a value with the common real type of E and V and the value of V. */ | 30 | /* Return a value with the common real type of E and V and the value of V. */ |
| 27 | #define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) | 31 | #define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) |
| 28 | 32 | ||
| @@ -67,6 +71,12 @@ | |||
| 67 | #define _GL_SIGNED_INT_MAXIMUM(e) \ | 71 | #define _GL_SIGNED_INT_MAXIMUM(e) \ |
| 68 | (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) | 72 | (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) |
| 69 | 73 | ||
| 74 | /* Work around OpenVMS incompatibility with C99. */ | ||
| 75 | #if !defined LLONG_MAX && defined __INT64_MAX | ||
| 76 | # define LLONG_MAX __INT64_MAX | ||
| 77 | # define LLONG_MIN __INT64_MIN | ||
| 78 | #endif | ||
| 79 | |||
| 70 | /* This include file assumes that signed types are two's complement without | 80 | /* This include file assumes that signed types are two's complement without |
| 71 | padding bits; the above macros have undefined behavior otherwise. | 81 | padding bits; the above macros have undefined behavior otherwise. |
| 72 | If this is a problem for you, please let us know how to fix it for your host. | 82 | If this is a problem for you, please let us know how to fix it for your host. |
| @@ -222,20 +232,25 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); | |||
| 222 | ? (a) < (min) >> (b) \ | 232 | ? (a) < (min) >> (b) \ |
| 223 | : (max) >> (b) < (a)) | 233 | : (max) >> (b) < (a)) |
| 224 | 234 | ||
| 225 | /* True if __builtin_add_overflow (A, B, P) works when P is null. */ | 235 | /* True if __builtin_add_overflow (A, B, P) works when P is non-null. */ |
| 226 | #define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__) | 236 | #define _GL_HAS_BUILTIN_OVERFLOW \ |
| 237 | (5 <= __GNUC__ || __has_builtin (__builtin_add_overflow)) | ||
| 238 | |||
| 239 | /* True if __builtin_add_overflow_p (A, B, C) works. */ | ||
| 240 | #define _GL_HAS_BUILTIN_OVERFLOW_P \ | ||
| 241 | (7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p)) | ||
| 227 | 242 | ||
| 228 | /* The _GL*_OVERFLOW macros have the same restrictions as the | 243 | /* The _GL*_OVERFLOW macros have the same restrictions as the |
| 229 | *_RANGE_OVERFLOW macros, except that they do not assume that operands | 244 | *_RANGE_OVERFLOW macros, except that they do not assume that operands |
| 230 | (e.g., A and B) have the same type as MIN and MAX. Instead, they assume | 245 | (e.g., A and B) have the same type as MIN and MAX. Instead, they assume |
| 231 | that the result (e.g., A + B) has that type. */ | 246 | that the result (e.g., A + B) has that type. */ |
| 232 | #if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL | 247 | #if _GL_HAS_BUILTIN_OVERFLOW_P |
| 233 | # define _GL_ADD_OVERFLOW(a, b, min, max) | 248 | # define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 234 | __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0) | 249 | __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) |
| 235 | # define _GL_SUBTRACT_OVERFLOW(a, b, min, max) | 250 | # define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ |
| 236 | __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0) | 251 | __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) |
| 237 | # define _GL_MULTIPLY_OVERFLOW(a, b, min, max) | 252 | # define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ |
| 238 | __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0) | 253 | __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) |
| 239 | #else | 254 | #else |
| 240 | # define _GL_ADD_OVERFLOW(a, b, min, max) \ | 255 | # define _GL_ADD_OVERFLOW(a, b, min, max) \ |
| 241 | ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ | 256 | ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ |
| @@ -315,7 +330,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); | |||
| 315 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) | 330 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) |
| 316 | #define INT_SUBTRACT_OVERFLOW(a, b) \ | 331 | #define INT_SUBTRACT_OVERFLOW(a, b) \ |
| 317 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) | 332 | _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) |
| 318 | #if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL | 333 | #if _GL_HAS_BUILTIN_OVERFLOW_P |
| 319 | # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) | 334 | # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) |
| 320 | #else | 335 | #else |
| 321 | # define INT_NEGATE_OVERFLOW(a) \ | 336 | # define INT_NEGATE_OVERFLOW(a) \ |
| @@ -349,10 +364,6 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); | |||
| 349 | #define INT_MULTIPLY_WRAPV(a, b, r) \ | 364 | #define INT_MULTIPLY_WRAPV(a, b, r) \ |
| 350 | _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) | 365 | _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW) |
| 351 | 366 | ||
| 352 | #ifndef __has_builtin | ||
| 353 | # define __has_builtin(x) 0 | ||
| 354 | #endif | ||
| 355 | |||
| 356 | /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: | 367 | /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: |
| 357 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 | 368 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 |
| 358 | https://llvm.org/bugs/show_bug.cgi?id=25390 | 369 | https://llvm.org/bugs/show_bug.cgi?id=25390 |
| @@ -369,7 +380,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); | |||
| 369 | the operation. BUILTIN is the builtin operation, and OVERFLOW the | 380 | the operation. BUILTIN is the builtin operation, and OVERFLOW the |
| 370 | overflow predicate. Return 1 if the result overflows. See above | 381 | overflow predicate. Return 1 if the result overflows. See above |
| 371 | for restrictions. */ | 382 | for restrictions. */ |
| 372 | #if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow) | 383 | #if _GL_HAS_BUILTIN_OVERFLOW |
| 373 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) | 384 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) |
| 374 | #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS | 385 | #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS |
| 375 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ | 386 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ |
| @@ -412,7 +423,7 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX); | |||
| 412 | # else | 423 | # else |
| 413 | # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ | 424 | # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ |
| 414 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ | 425 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ |
| 415 | long int, LONG_MIN, LONG_MAX)) | 426 | long int, LONG_MIN, LONG_MAX) |
| 416 | # endif | 427 | # endif |
| 417 | #endif | 428 | #endif |
| 418 | 429 | ||
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h index 44f16441c79..53e6556c610 100644 --- a/lib/xalloc-oversized.h +++ b/lib/xalloc-oversized.h | |||
| @@ -43,16 +43,8 @@ | |||
| 43 | nonnegative. This is a macro, not a function, so that it | 43 | nonnegative. This is a macro, not a function, so that it |
| 44 | works correctly even when SIZE_MAX < N. */ | 44 | works correctly even when SIZE_MAX < N. */ |
| 45 | 45 | ||
| 46 | /* GCC 7 __builtin_mul_overflow should easily compute this. See: | 46 | #if 7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p) |
| 47 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68120 */ | 47 | # define xalloc_oversized(n, s) __builtin_mul_overflow_p (n, s, (size_t) 1) |
| 48 | #if 7 <= __GNUC__ | ||
| 49 | # define xalloc_oversized(n, s) __builtin_mul_overflow (n, s, (size_t *) NULL) | ||
| 50 | |||
| 51 | /* GCC 5 and Clang __builtin_mul_overflow needs a temporary, and | ||
| 52 | should be used only for non-constant operands, so that | ||
| 53 | xalloc_oversized is a constant expression if both arguments are. | ||
| 54 | Do not use this if pedantic, since pedantic GCC issues a diagnostic | ||
| 55 | for ({ ... }). */ | ||
| 56 | #elif ((5 <= __GNUC__ \ | 48 | #elif ((5 <= __GNUC__ \ |
| 57 | || (__has_builtin (__builtin_mul_overflow) \ | 49 | || (__has_builtin (__builtin_mul_overflow) \ |
| 58 | && __has_builtin (__builtin_constant_p))) \ | 50 | && __has_builtin (__builtin_constant_p))) \ |