diff options
| author | Paul Eggert | 2017-04-15 22:22:49 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-04-15 22:23:05 -0700 |
| commit | 0ef7f64407525a1e1bcc8aef4d1fd19a1cf60ec6 (patch) | |
| tree | 8ef5acb8ebb49d0fe5113af24fc0cb8ab918af57 /lib | |
| parent | 23d3eeb798c7edc27898b0dbd4c2364a6ca6247d (diff) | |
| download | emacs-0ef7f64407525a1e1bcc8aef4d1fd19a1cf60ec6.tar.gz emacs-0ef7f64407525a1e1bcc8aef4d1fd19a1cf60ec6.zip | |
Merge from gnulib
This incorporates:
2017-04-14 intprops: try to avoid tickling similar bugs
2017-04-14 intprops: port to Oracle Studio 12.3 x86
* doc/misc/texinfo.tex, lib/intprops.h: Copy from gnulib.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/intprops.h | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/intprops.h b/lib/intprops.h index 85ed61f8d8c..1ea9647e16e 100644 --- a/lib/intprops.h +++ b/lib/intprops.h | |||
| @@ -389,10 +389,10 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); | |||
| 389 | (_Generic \ | 389 | (_Generic \ |
| 390 | (*(r), \ | 390 | (*(r), \ |
| 391 | signed char: \ | 391 | signed char: \ |
| 392 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \ | 392 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| 393 | signed char, SCHAR_MIN, SCHAR_MAX), \ | 393 | signed char, SCHAR_MIN, SCHAR_MAX), \ |
| 394 | short int: \ | 394 | short int: \ |
| 395 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \ | 395 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| 396 | short int, SHRT_MIN, SHRT_MAX), \ | 396 | short int, SHRT_MIN, SHRT_MAX), \ |
| 397 | int: \ | 397 | int: \ |
| 398 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ | 398 | _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| @@ -406,10 +406,10 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); | |||
| 406 | #else | 406 | #else |
| 407 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ | 407 | # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ |
| 408 | (sizeof *(r) == sizeof (signed char) \ | 408 | (sizeof *(r) == sizeof (signed char) \ |
| 409 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \ | 409 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| 410 | signed char, SCHAR_MIN, SCHAR_MAX) \ | 410 | signed char, SCHAR_MIN, SCHAR_MAX) \ |
| 411 | : sizeof *(r) == sizeof (short int) \ | 411 | : sizeof *(r) == sizeof (short int) \ |
| 412 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \ | 412 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| 413 | short int, SHRT_MIN, SHRT_MAX) \ | 413 | short int, SHRT_MIN, SHRT_MAX) \ |
| 414 | : sizeof *(r) == sizeof (int) \ | 414 | : sizeof *(r) == sizeof (int) \ |
| 415 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ | 415 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ |
| @@ -431,9 +431,8 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); | |||
| 431 | 431 | ||
| 432 | /* Store the low-order bits of A <op> B into *R, where the operation | 432 | /* Store the low-order bits of A <op> B into *R, where the operation |
| 433 | is given by OP. Use the unsigned type UT for calculation to avoid | 433 | is given by OP. Use the unsigned type UT for calculation to avoid |
| 434 | overflow problems. *R's type is T, with extremal values TMIN and | 434 | overflow problems. *R's type is T, with extrema TMIN and TMAX. |
| 435 | TMAX. T must be a signed integer type. Return 1 if the result | 435 | T must be a signed integer type. Return 1 if the result overflows. */ |
| 436 | overflows. */ | ||
| 437 | #define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ | 436 | #define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ |
| 438 | (sizeof ((a) op (b)) < sizeof (t) \ | 437 | (sizeof ((a) op (b)) < sizeof (t) \ |
| 439 | ? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \ | 438 | ? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \ |
| @@ -442,17 +441,27 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH); | |||
| 442 | ((overflow (a, b) \ | 441 | ((overflow (a, b) \ |
| 443 | || (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \ | 442 | || (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \ |
| 444 | || (tmax) < ((a) op (b))) \ | 443 | || (tmax) < ((a) op (b))) \ |
| 445 | ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 1) \ | 444 | ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \ |
| 446 | : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 0)) | 445 | : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0)) |
| 447 | 446 | ||
| 448 | /* Return A <op> B, where the operation is given by OP. Use the | 447 | /* Return the low-order bits of A <op> B, where the operation is given |
| 449 | unsigned type UT for calculation to avoid overflow problems. | 448 | by OP. Use the unsigned type UT for calculation to avoid undefined |
| 450 | Convert the result to type T without overflow by subtracting TMIN | 449 | behavior on signed integer overflow, and convert the result to type T. |
| 451 | from large values before converting, and adding it afterwards. | 450 | UT is at least as wide as T and is no narrower than unsigned int, |
| 452 | Compilers can optimize all the operations except OP. */ | 451 | T is two's complement, and there is no padding or trap representations. |
| 453 | #define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t, tmin, tmax) \ | 452 | Assume that converting UT to T yields the low-order bits, as is |
| 454 | (((ut) (a) op (ut) (b)) <= (tmax) \ | 453 | done in all known two's-complement C compilers. E.g., see: |
| 455 | ? (t) ((ut) (a) op (ut) (b)) \ | 454 | https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html |
| 456 | : ((t) (((ut) (a) op (ut) (b)) - (tmin)) + (tmin))) | 455 | |
| 456 | According to the C standard, converting UT to T yields an | ||
| 457 | implementation-defined result or signal for values outside T's | ||
| 458 | range. However, code that works around this theoretical problem | ||
| 459 | runs afoul of a compiler bug in Oracle Studio 12.3 x86. See: | ||
| 460 | http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html | ||
| 461 | As the compiler bug is real, don't try to work around the | ||
| 462 | theoretical problem. */ | ||
| 463 | |||
| 464 | #define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \ | ||
| 465 | ((t) ((ut) (a) op (ut) (b))) | ||
| 457 | 466 | ||
| 458 | #endif /* _GL_INTPROPS_H */ | 467 | #endif /* _GL_INTPROPS_H */ |