Index: libm/common/s_llround.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_llround.c,v retrieving revision 1.1 diff -p -u -r1.1 s_llround.c --- libm/common/s_llround.c 25 Mar 2009 19:13:01 -0000 1.1 +++ libm/common/s_llround.c 16 Jul 2010 16:44:13 -0000 @@ -49,7 +49,9 @@ llround(double x) else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1) { if (exponent_less_1023 >= 52) - result = ((long long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52)); + result = SAFE_LEFT_SHIFT ((long long int) msw, + (exponent_less_1023 - 20)) + | SAFE_LEFT_SHIFT (lsw, (exponent_less_1023 - 52)); else { unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20)); Index: libm/common/s_lround.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_lround.c,v retrieving revision 1.2 diff -p -u -r1.2 s_lround.c --- libm/common/s_lround.c 25 Mar 2009 19:13:01 -0000 1.2 +++ libm/common/s_lround.c 16 Jul 2010 16:44:13 -0000 @@ -90,7 +90,8 @@ ANSI C, POSIX else if (exponent_less_1023 < (8 * sizeof (long int)) - 1) { if (exponent_less_1023 >= 52) - result = ((long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52)); + result = SAFE_LEFT_SHIFT ((long int) msw, (exponent_less_1023 - 20)) + | SAFE_LEFT_SHIFT (lsw, (exponent_less_1023 - 52)); else { unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20)); Index: libm/common/fdlibm.h =================================================================== RCS file: /cvs/src/src/newlib/libm/common/fdlibm.h,v retrieving revision 1.7 diff -p -u -r1.7 fdlibm.h --- libm/common/fdlibm.h 17 Nov 2009 22:35:46 -0000 1.7 +++ libm/common/fdlibm.h 16 Jul 2010 16:44:14 -0000 @@ -361,3 +361,13 @@ do { \ sf_u.word = (i); \ (d) = sf_u.value; \ } while (0) + +/* Macros to avoid undefined behaviour that can arise if the amount + of a shift is exactly equal to the size of the shifted operand. */ + +#define SAFE_LEFT_SHIFT(op,amt) \ + (((amt) < 8 * sizeof(op)) ? ((op) << (amt)) : 0) + +#define SAFE_RIGHT_SHIFT(op,amt) \ + (((amt) < 8 * sizeof(op)) ? ((op) >> (amt)) : 0) +