Commit 64685ffa by Richard Stallman

Deleted casts to void.

(emdnorm, eifrac, euifrac, mtherr): Replace
unconditional `pedwarn' by `warning' conditional on `extra_warnings'.
(toe24, todec): Use ERANGE to flag overflow on (non-IEEE)
machines that do not have infinity.
(etoasc): Check explicitly for overflow of leading decimal digit.
(asctoeg): Test for, and immediately reject, out-of-bounds
decimal exponent inputs.
(at top level): Include errno.h; reference errno, warning, extra_warnings.

From-SVN: r4300
parent 0a05e9c9
...@@ -21,10 +21,14 @@ along with GNU CC; see the file COPYING. If not, write to ...@@ -21,10 +21,14 @@ along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "config.h" #include "config.h"
#include "tree.h" #include "tree.h"
#ifndef errno
extern int errno;
#endif
/* To enable support of XFmode extended real floating point, define /* To enable support of XFmode extended real floating point, define
LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h). LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
...@@ -249,7 +253,8 @@ do { EMUSHORT w[4]; \ ...@@ -249,7 +253,8 @@ do { EMUSHORT w[4]; \
#endif /* not REAL_ARITHMETIC */ #endif /* not REAL_ARITHMETIC */
#endif /* no XFmode */ #endif /* no XFmode */
void pedwarn (); void warning ();
extern int extra_warnings;
int ecmp (), enormlz (), eshift (), eisneg (), eisinf (); int ecmp (), enormlz (), eshift (), eisneg (), eisinf ();
void eadd (), esub (), emul (), ediv (); void eadd (), esub (), emul (), ediv ();
void eshup1 (), eshup8 (), eshup6 (), eshdn1 (), eshdn8 (), eshdn6 (); void eshup1 (), eshup8 (), eshup6 (), eshdn1 (), eshdn8 (), eshdn6 ();
...@@ -1935,7 +1940,8 @@ emdnorm (s, lost, subflg, exp, rcntrl) ...@@ -1935,7 +1940,8 @@ emdnorm (s, lost, subflg, exp, rcntrl)
s[1] = 32767; s[1] = 32767;
for (i = 2; i < NI - 1; i++) for (i = 2; i < NI - 1; i++)
s[i] = 0; s[i] = 0;
pedwarn ("floating point overflow"); if (extra_warnings)
warning ("floating point overflow");
#else #else
s[1] = 32766; s[1] = 32766;
s[2] = 0; s[2] = 0;
...@@ -2321,7 +2327,7 @@ e53toe (e, y) ...@@ -2321,7 +2327,7 @@ e53toe (e, y)
*p++ = *e++; *p++ = *e++;
*p++ = *e++; *p++ = *e++;
#endif #endif
(void) eshift (yy, -5); eshift (yy, -5);
if (denorm) if (denorm)
{ /* if zero exponent, then normalize the significand */ { /* if zero exponent, then normalize the significand */
if ((k = enormlz (yy)) > NBITS) if ((k = enormlz (yy)) > NBITS)
...@@ -2434,7 +2440,7 @@ e24toe (e, y) ...@@ -2434,7 +2440,7 @@ e24toe (e, y)
++e; ++e;
*p++ = *e++; *p++ = *e++;
#endif #endif
(void) eshift (yy, -8); eshift (yy, -8);
if (denorm) if (denorm)
{ /* if zero exponent, then normalize the significand */ { /* if zero exponent, then normalize the significand */
if ((k = enormlz (yy)) > NBITS) if ((k = enormlz (yy)) > NBITS)
...@@ -2616,12 +2622,12 @@ toe53 (x, y) ...@@ -2616,12 +2622,12 @@ toe53 (x, y)
} }
if (i == 0) if (i == 0)
{ {
(void) eshift (x, 4); eshift (x, 4);
} }
else else
{ {
i <<= 4; i <<= 4;
(void) eshift (x, 5); eshift (x, 5);
} }
i |= *p++ & (unsigned EMUSHORT) 0x0f; /* *p = xi[M] */ i |= *p++ & (unsigned EMUSHORT) 0x0f; /* *p = xi[M] */
*y |= (unsigned EMUSHORT) i; /* high order output already has sign bit set */ *y |= (unsigned EMUSHORT) i; /* high order output already has sign bit set */
...@@ -2691,8 +2697,9 @@ toe24 (x, y) ...@@ -2691,8 +2697,9 @@ toe24 (x, y)
*y = 0x8000; /* output sign bit */ *y = 0x8000; /* output sign bit */
i = *p++; i = *p++;
/* Handle overflow cases. */
if (i >= 255) if (i >= 255)
{ /* Saturate at largest number less than infinity. */ {
#ifdef INFINITY #ifdef INFINITY
*y |= (unsigned EMUSHORT) 0x7f80; *y |= (unsigned EMUSHORT) 0x7f80;
#ifdef IBMPC #ifdef IBMPC
...@@ -2705,7 +2712,7 @@ toe24 (x, y) ...@@ -2705,7 +2712,7 @@ toe24 (x, y)
++y; ++y;
*y = 0; *y = 0;
#endif #endif
#else #else /* no INFINITY */
*y |= (unsigned EMUSHORT) 0x7f7f; *y |= (unsigned EMUSHORT) 0x7f7f;
#ifdef IBMPC #ifdef IBMPC
*(--y) = 0xffff; *(--y) = 0xffff;
...@@ -2717,17 +2724,20 @@ toe24 (x, y) ...@@ -2717,17 +2724,20 @@ toe24 (x, y)
++y; ++y;
*y = 0xffff; *y = 0xffff;
#endif #endif
#ifdef ERANGE
errno = ERANGE;
#endif #endif
#endif /* no INFINITY */
return; return;
} }
if (i == 0) if (i == 0)
{ {
(void) eshift (x, 7); eshift (x, 7);
} }
else else
{ {
i <<= 7; i <<= 7;
(void) eshift (x, 8); eshift (x, 8);
} }
i |= *p++ & (unsigned EMUSHORT) 0x7f; /* *p = xi[M] */ i |= *p++ & (unsigned EMUSHORT) 0x7f; /* *p = xi[M] */
*y |= i; /* high order output already has sign bit set */ *y |= i; /* high order output already has sign bit set */
...@@ -2941,8 +2951,9 @@ eifrac (x, i, frac) ...@@ -2941,8 +2951,9 @@ eifrac (x, i, frac)
*i = ((unsigned long) 1) << (HOST_BITS_PER_LONG - 1); *i = ((unsigned long) 1) << (HOST_BITS_PER_LONG - 1);
else else
*i = (((unsigned long) 1) << (HOST_BITS_PER_LONG - 1)) - 1; *i = (((unsigned long) 1) << (HOST_BITS_PER_LONG - 1)) - 1;
(void) eshift (xi, k); eshift (xi, k);
pedwarn ("Overflow on truncation to integer"); if (extra_warnings)
warning ("overflow on truncation to integer");
goto lab11; goto lab11;
} }
...@@ -2953,7 +2964,7 @@ eifrac (x, i, frac) ...@@ -2953,7 +2964,7 @@ eifrac (x, i, frac)
; then complete the shift to get the fraction. ; then complete the shift to get the fraction.
*/ */
k -= 16; k -= 16;
(void) eshift (xi, k); eshift (xi, k);
*i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]); *i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]);
eshup6 (xi); eshup6 (xi);
...@@ -2961,7 +2972,7 @@ eifrac (x, i, frac) ...@@ -2961,7 +2972,7 @@ eifrac (x, i, frac)
} }
/* shift not more than 16 bits */ /* shift not more than 16 bits */
(void) eshift (xi, k); eshift (xi, k);
*i = (long) xi[M] & 0xffff; *i = (long) xi[M] & 0xffff;
lab10: lab10:
...@@ -3017,8 +3028,9 @@ euifrac (x, i, frac) ...@@ -3017,8 +3028,9 @@ euifrac (x, i, frac)
; and correct fraction ; and correct fraction
*/ */
*i = ~(0L); *i = ~(0L);
(void) eshift (xi, k); eshift (xi, k);
pedwarn ("Overflow on truncation to unsigned integer"); if (extra_warnings)
warning ("overflow on truncation to unsigned integer");
goto lab10; goto lab10;
} }
...@@ -3029,7 +3041,7 @@ euifrac (x, i, frac) ...@@ -3029,7 +3041,7 @@ euifrac (x, i, frac)
; then complete the shift to get the fraction. ; then complete the shift to get the fraction.
*/ */
k -= 16; k -= 16;
(void) eshift (xi, k); eshift (xi, k);
*i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]); *i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]);
eshup6 (xi); eshup6 (xi);
...@@ -3037,7 +3049,7 @@ euifrac (x, i, frac) ...@@ -3037,7 +3049,7 @@ euifrac (x, i, frac)
} }
/* shift not more than 16 bits */ /* shift not more than 16 bits */
(void) eshift (xi, k); eshift (xi, k);
*i = (long) xi[M] & 0xffff; *i = (long) xi[M] & 0xffff;
lab10: lab10:
...@@ -3540,13 +3552,27 @@ etoasc (x, string, ndigs) ...@@ -3540,13 +3552,27 @@ etoasc (x, string, ndigs)
*s++ = '-'; *s++ = '-';
else else
*s++ = ' '; *s++ = ' ';
*s++ = (char) digit + '0';
*s++ = '.';
/* Examine number of digits requested by caller. */ /* Examine number of digits requested by caller. */
if (ndigs < 0) if (ndigs < 0)
ndigs = 0; ndigs = 0;
if (ndigs > NDEC) if (ndigs > NDEC)
ndigs = NDEC; ndigs = NDEC;
if (digit == 10)
{
*s++ = '1';
*s++ = '.';
if (ndigs > 0)
{
*s++ = '0';
ndigs -= 1;
}
expon += 1;
}
else
{
*s++ = (char )digit + '0';
*s++ = '.';
}
/* Generate digits after the decimal point. */ /* Generate digits after the decimal point. */
for (k = 0; k <= ndigs; k++) for (k = 0; k <= ndigs; k++)
{ {
...@@ -3809,9 +3835,7 @@ asctoeg (ss, y, oprec) ...@@ -3809,9 +3835,7 @@ asctoeg (ss, y, oprec)
goto daldone; goto daldone;
case 'i': case 'i':
case 'I': case 'I':
ecleaz (yy); goto infinite;
yy[E] = 0x7fff; /* infinity */
goto aexit;
default: default:
error: error:
mtherr ("asctoe", DOMAIN); mtherr ("asctoe", DOMAIN);
...@@ -3840,9 +3864,29 @@ asctoeg (ss, y, oprec) ...@@ -3840,9 +3864,29 @@ asctoeg (ss, y, oprec)
{ {
exp *= 10; exp *= 10;
exp += *s++ - '0'; exp += *s++ - '0';
if (exp > 4956)
{
if (esign < 0)
goto zero;
else
goto infinite;
}
} }
if (esign < 0) if (esign < 0)
exp = -exp; exp = -exp;
if (exp > 4932)
{
infinite:
ecleaz (yy);
yy[E] = 0x7fff; /* infinity */
goto aexit;
}
if (exp < -4956)
{
zero:
ecleaz (yy);
goto aexit;
}
daldone: daldone:
nexp = exp - nexp; nexp = exp - nexp;
...@@ -4247,7 +4291,8 @@ mtherr (name, code) ...@@ -4247,7 +4291,8 @@ mtherr (name, code)
if ((code <= 0) || (code >= 6)) if ((code <= 0) || (code >= 6))
code = 0; code = 0;
sprintf (errstr, "\n%s %s error\n", name, ermsg[code]); sprintf (errstr, "\n%s %s error\n", name, ermsg[code]);
pedwarn (errstr); if (extra_warnings)
warning (errstr);
/* Set global error message word */ /* Set global error message word */
merror = code + 1; merror = code + 1;
...@@ -4429,6 +4474,9 @@ todec (x, y) ...@@ -4429,6 +4474,9 @@ todec (x, y)
*y++ = 0xffff; *y++ = 0xffff;
*y++ = 0xffff; *y++ = 0xffff;
*y++ = 0xffff; *y++ = 0xffff;
#ifdef ERANGE
errno = ERANGE;
#endif
return; return;
} }
i &= 0377; i &= 0377;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment