From 8c5e817587081e6be58a71ef8970934f03d68bad Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 19 May 2011 01:36:25 -0700 Subject: [PATCH] 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 . (cherry picked from commit 8cc0fee0550bac55e1c1244366308eed1d16bb82) --- ChangeLog | 5 +++++ lib/intprops.h | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8cba5270..9e2d57c42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-05-19 Paul Eggert + 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 + . + 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 diff --git a/lib/intprops.h b/lib/intprops.h index a84bd6af5..9107a4bbe 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -179,16 +179,21 @@ : 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 + . */ #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. */ -- 2.11.0