intprops: work around C compiler bugs
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 May 2011 08:36:25 +0000 (01:36 -0700)
committerIan Beckwith <ianb@erislabs.net>
Thu, 9 Jun 2011 17:13:48 +0000 (18:13 +0100)
* lib/intprops.h (INT_MULTIPLY_RANGE_OVERFLOW): Work around compiler
bug in Sun C 5.11 2010/08/13 and other compilers; see
<http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.
(cherry picked from commit 8cc0fee0550bac55e1c1244366308eed1d16bb82)

ChangeLog
lib/intprops.h

index b8cba52..9e2d57c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-05-19  Paul Eggert  <eggert@cs.ucla.edu>
 
+       intprops: work around C compiler bugs
+       * lib/intprops.h (INT_MULTIPLY_RANGE_OVERFLOW): Work around compiler
+       bug in Sun C 5.11 2010/08/13 and other compilers; see
+       <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.
+
        intprops: TYPE_IS_INTEGER, TYPE_SIGNED not integer constant exprs
        * doc/intprops.texi (Integer Type Determination): Fix
        documentation for TYPE_IS_INTEGER: it returns an constant
index a84bd6a..9107a4b 100644 (file)
    : 0 < (a))
 
 /* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
-   See above for restrictions.  */
+   See above for restrictions.  Avoid && and || as they tickle
+   bugs in Sun C 5.11 2010/08/13 and other compilers; see
+   <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.  */
 #define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max)     \
   ((b) < 0                                              \
    ? ((a) < 0                                           \
       ? (a) < (max) / (b)                               \
-      : (b) < -1 && (min) / (b) < (a))                  \
-   : (0 < (b)                                           \
-      && ((a) < 0                                       \
-          ? (a) < (min) / (b)                           \
-          : (max) / (b) < (a))))
+      : (b) == -1                                       \
+      ? 0                                               \
+      : (min) / (b) < (a))                              \
+   : (b) == 0                                           \
+   ? 0                                                  \
+   : ((a) < 0                                           \
+      ? (a) < (min) / (b)                               \
+      : (max) / (b) < (a)))
 
 /* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
    See above for restrictions.  Do not check for division by zero.  */