diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/intprops.h | 38 | ||||
| -rw-r--r-- | lib/stdint.in.h | 2 |
2 files changed, 23 insertions, 17 deletions
diff --git a/lib/intprops.h b/lib/intprops.h index a84bd6af531..293204ab43a 100644 --- a/lib/intprops.h +++ b/lib/intprops.h | |||
| @@ -27,6 +27,10 @@ | |||
| 27 | E should not have side effects. */ | 27 | E should not have side effects. */ |
| 28 | #define _GL_INT_CONVERT(e, v) ((e) - (e) + (v)) | 28 | #define _GL_INT_CONVERT(e, v) ((e) - (e) + (v)) |
| 29 | 29 | ||
| 30 | /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see | ||
| 31 | <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */ | ||
| 32 | #define _GL_INT_NEGATE_CONVERT(e, v) ((e) - (e) - (v)) | ||
| 33 | |||
| 30 | /* The extra casts in the following macros work around compiler bugs, | 34 | /* The extra casts in the following macros work around compiler bugs, |
| 31 | e.g., in Cray C 5.0.3.0. */ | 35 | e.g., in Cray C 5.0.3.0. */ |
| 32 | 36 | ||
| @@ -50,7 +54,7 @@ | |||
| 50 | 54 | ||
| 51 | /* Return 1 if the integer expression E, after integer promotion, has | 55 | /* Return 1 if the integer expression E, after integer promotion, has |
| 52 | a signed type. E should not have side effects. */ | 56 | a signed type. E should not have side effects. */ |
| 53 | #define _GL_INT_SIGNED(e) (_GL_INT_CONVERT (e, -1) < 0) | 57 | #define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) |
| 54 | 58 | ||
| 55 | 59 | ||
| 56 | /* Minimum and maximum values for integer types and expressions. These | 60 | /* Minimum and maximum values for integer types and expressions. These |
| @@ -79,7 +83,7 @@ | |||
| 79 | #define _GL_INT_MAXIMUM(e) \ | 83 | #define _GL_INT_MAXIMUM(e) \ |
| 80 | (_GL_INT_SIGNED (e) \ | 84 | (_GL_INT_SIGNED (e) \ |
| 81 | ? _GL_SIGNED_INT_MAXIMUM (e) \ | 85 | ? _GL_SIGNED_INT_MAXIMUM (e) \ |
| 82 | : _GL_INT_CONVERT (e, -1)) | 86 | : _GL_INT_NEGATE_CONVERT (e, 1)) |
| 83 | #define _GL_SIGNED_INT_MAXIMUM(e) \ | 87 | #define _GL_SIGNED_INT_MAXIMUM(e) \ |
| 84 | (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) | 88 | (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) |
| 85 | 89 | ||
| @@ -179,16 +183,21 @@ | |||
| 179 | : 0 < (a)) | 183 | : 0 < (a)) |
| 180 | 184 | ||
| 181 | /* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. | 185 | /* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. |
| 182 | See above for restrictions. */ | 186 | See above for restrictions. Avoid && and || as they tickle |
| 187 | bugs in Sun C 5.11 2010/08/13 and other compilers; see | ||
| 188 | <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */ | ||
| 183 | #define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ | 189 | #define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ |
| 184 | ((b) < 0 \ | 190 | ((b) < 0 \ |
| 185 | ? ((a) < 0 \ | 191 | ? ((a) < 0 \ |
| 186 | ? (a) < (max) / (b) \ | 192 | ? (a) < (max) / (b) \ |
| 187 | : (b) < -1 && (min) / (b) < (a)) \ | 193 | : (b) == -1 \ |
| 188 | : (0 < (b) \ | 194 | ? 0 \ |
| 189 | && ((a) < 0 \ | 195 | : (min) / (b) < (a)) \ |
| 190 | ? (a) < (min) / (b) \ | 196 | : (b) == 0 \ |
| 191 | : (max) / (b) < (a)))) | 197 | ? 0 \ |
| 198 | : ((a) < 0 \ | ||
| 199 | ? (a) < (min) / (b) \ | ||
| 200 | : (max) / (b) < (a))) | ||
| 192 | 201 | ||
| 193 | /* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. | 202 | /* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. |
| 194 | See above for restrictions. Do not check for division by zero. */ | 203 | See above for restrictions. Do not check for division by zero. */ |
| @@ -234,11 +243,11 @@ | |||
| 234 | (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ | 243 | (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ |
| 235 | || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) | 244 | || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) |
| 236 | #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ | 245 | #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ |
| 237 | ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ | 246 | ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ |
| 238 | : (a) < 0 ? (b) <= (a) + (b) - 1 \ | 247 | : (a) < 0 ? (b) <= (a) + (b) - 1 \ |
| 239 | : (b) < 0 && (a) + (b) <= (a)) | 248 | : (b) < 0 && (a) + (b) <= (a)) |
| 240 | #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ | 249 | #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ |
| 241 | ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ | 250 | ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ |
| 242 | : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ | 251 | : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ |
| 243 | : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) | 252 | : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) |
| 244 | 253 | ||
| @@ -302,13 +311,10 @@ | |||
| 302 | /* Return 1 if the expression A <op> B would overflow, | 311 | /* Return 1 if the expression A <op> B would overflow, |
| 303 | where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, | 312 | where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, |
| 304 | assuming MIN and MAX are the minimum and maximum for the result type. | 313 | assuming MIN and MAX are the minimum and maximum for the result type. |
| 305 | 314 | Arguments should be free of side effects. */ | |
| 306 | This macro assumes that A | B is a valid integer if both A and B are, | ||
| 307 | which is true of all known practical hosts. If this is a problem | ||
| 308 | for you, please let us know how to fix it for your host. */ | ||
| 309 | #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ | 315 | #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ |
| 310 | op_result_overflow (a, b, \ | 316 | op_result_overflow (a, b, \ |
| 311 | _GL_INT_MINIMUM ((a) | (b)), \ | 317 | _GL_INT_MINIMUM ((b) - (b) + (a)), \ |
| 312 | _GL_INT_MAXIMUM ((a) | (b))) | 318 | _GL_INT_MAXIMUM ((b) - (b) + (a))) |
| 313 | 319 | ||
| 314 | #endif /* _GL_INTPROPS_H */ | 320 | #endif /* _GL_INTPROPS_H */ |
diff --git a/lib/stdint.in.h b/lib/stdint.in.h index b32227bb04c..376b96a785d 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h | |||
| @@ -93,7 +93,7 @@ | |||
| 93 | 93 | ||
| 94 | #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H | 94 | #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H |
| 95 | 95 | ||
| 96 | /* Minimum and maximum values for a integer type under the usual assumption. | 96 | /* Minimum and maximum values for an integer type under the usual assumption. |
| 97 | Return an unspecified value if BITS == 0, adding a check to pacify | 97 | Return an unspecified value if BITS == 0, adding a check to pacify |
| 98 | picky compilers. */ | 98 | picky compilers. */ |
| 99 | 99 | ||