From 92c71a1c8324e3f0776fd0edb3fc400b4d04a592 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 19 May 2011 19:16:04 -0700 Subject: [PATCH] intprops: work around IRIX 6.5 cc bug with 0u - 0u + -1 See http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html * lib/intprops.h (_GL_INT_NEGATE_CONVERT): New macro. (_GL_INT_SIGNED, _GL_INT_MAXIMUM, _GL_DIVIDE_OVERFLOW): (_GL_REMAINDER_OVERFLOW): Use it. --- ChangeLog | 6 ++++++ lib/intprops.h | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5065b4b497..75f9b1d170 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-05-19 Paul Eggert + intprops: work around IRIX 6.5 cc bug with 0u - 0u + -1 + See http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html + * lib/intprops.h (_GL_INT_NEGATE_CONVERT): New macro. + (_GL_INT_SIGNED, _GL_INT_MAXIMUM, _GL_DIVIDE_OVERFLOW): + (_GL_REMAINDER_OVERFLOW): Use it. + intprops-tests: revert unsigned part of previous change * tests/test-intprops.c (UINT_MAX, ULONG_MAX, UINTMAX_MAX, U0, U1): Remove; they weren't actually needed. All uses of U0 and U1 removed, diff --git a/lib/intprops.h b/lib/intprops.h index 9107a4bbea..bd9f04042e 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -27,6 +27,10 @@ E should not have side effects. */ #define _GL_INT_CONVERT(e, v) ((e) - (e) + (v)) +/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see + . */ +#define _GL_INT_NEGATE_CONVERT(e, v) ((e) - (e) - (v)) + /* The extra casts in the following macros work around compiler bugs, e.g., in Cray C 5.0.3.0. */ @@ -50,7 +54,7 @@ /* Return 1 if the integer expression E, after integer promotion, has a signed type. E should not have side effects. */ -#define _GL_INT_SIGNED(e) (_GL_INT_CONVERT (e, -1) < 0) +#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) /* Minimum and maximum values for integer types and expressions. These @@ -79,7 +83,7 @@ #define _GL_INT_MAXIMUM(e) \ (_GL_INT_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \ - : _GL_INT_CONVERT (e, -1)) + : _GL_INT_NEGATE_CONVERT (e, 1)) #define _GL_SIGNED_INT_MAXIMUM(e) \ (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) @@ -239,11 +243,11 @@ (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ - ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ : (a) < 0 ? (b) <= (a) + (b) - 1 \ : (b) < 0 && (a) + (b) <= (a)) #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ - ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) -- 2.30.2