ruby-changes:11711
From: akr <ko1@a...>
Date: Thu, 7 May 2009 02:02:41 +0900 (JST)
Subject: [ruby-changes:11711] Ruby:r23353 (ruby_1_8): * util.c: suppress strict-aliasing warning with gcc-4.4.0 -O2 to fix
akr 2009-05-07 02:02:29 +0900 (Thu, 07 May 2009) New Revision: 23353 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23353 Log: * util.c: suppress strict-aliasing warning with gcc-4.4.0 -O2 to fix infinite loop by ruby -e "1.402e-45" . Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/util.c Index: ruby_1_8/util.c =================================================================== --- ruby_1_8/util.c (revision 23352) +++ ruby_1_8/util.c (revision 23353) @@ -956,24 +956,26 @@ typedef union { double d; ULong L[2]; } U; #ifdef YES_ALIAS -#define dval(x) x -#ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((ULong *)&x)[1] -#define word1(x) ((ULong *)&x)[0] +typedef double double_u; +# define dval(x) x +# ifdef IEEE_LITTLE_ENDIAN +# define word0(x) (((ULong *)&x)[1]) +# define word1(x) (((ULong *)&x)[0]) +# else +# define word0(x) (((ULong *)&x)[0]) +# define word1(x) (((ULong *)&x)[1]) +# endif #else -#define word0(x) ((ULong *)&x)[0] -#define word1(x) ((ULong *)&x)[1] +typedef U double_u; +# ifdef IEEE_LITTLE_ENDIAN +# define word0(x) (x.L[1]) +# define word1(x) (x.L[0]) +# else +# define word0(x) (x.L[0]) +# define word1(x) (x.L[1]) +# endif +# define dval(x) (x.d) #endif -#else -#ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((U*)&x)->L[1] -#define word1(x) ((U*)&x)->L[0] -#else -#define word0(x) ((U*)&x)->L[0] -#define word1(x) ((U*)&x)->L[1] -#endif -#define dval(x) ((U*)&x)->d -#endif /* The following definition of Storeinc is appropriate for MIPS processors. * An alternative that might be better on some machines is @@ -1702,10 +1704,11 @@ } static double -ulp(double x) +ulp(double x_) { register Long L; - double a; + double_u x, a; + dval(x) = x_; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; #ifndef Avoid_Underflow @@ -1743,7 +1746,7 @@ { ULong *xa, *xa0, w, y, z; int k; - double d; + double_u d; #ifdef VAX ULong d0, d1; #else @@ -1804,8 +1807,9 @@ } static Bigint * -d2b(double d, int *e, int *bits) +d2b(double d_, int *e, int *bits) { + double_u d; Bigint *b; int de, k; ULong *x, y, z; @@ -1814,6 +1818,9 @@ #endif #ifdef VAX ULong d0, d1; +#endif + dval(d) = d_; +#ifdef VAX d0 = word0(d) >> 16 | word0(d) << 16; d1 = word1(d) >> 16 | word1(d) << 16; #else @@ -1939,7 +1946,7 @@ static double ratio(Bigint *a, Bigint *b) { - double da, db; + double_u da, db; int k, ka, kb; dval(da) = b2d(a, &ka); @@ -2098,7 +2105,8 @@ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; const char *s, *s0, *s1; - double aadj, aadj1, adj, rv, rv0; + double aadj, adj; + double_u aadj1, rv, rv0; Long L; ULong y, z; Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; @@ -2797,14 +2805,14 @@ } if ((aadj = ratio(delta, bs)) <= 2.) { if (dsign) - aadj = aadj1 = 1.; + aadj = dval(aadj1) = 1.; else if (word1(rv) || word0(rv) & Bndry_mask) { #ifndef Sudden_Underflow if (word1(rv) == Tiny1 && !word0(rv)) goto undfl; #endif aadj = 1.; - aadj1 = -1.; + dval(aadj1) = -1.; } else { /* special case -- power of FLT_RADIX to be */ @@ -2814,12 +2822,12 @@ aadj = 1./FLT_RADIX; else aadj *= 0.5; - aadj1 = -aadj; + dval(aadj1) = -aadj; } } else { aadj *= 0.5; - aadj1 = dsign ? aadj : -aadj; + dval(aadj1) = dsign ? aadj : -aadj; #ifdef Check_FLT_ROUNDS switch (Rounding) { case 2: /* towards +infinity */ @@ -2831,7 +2839,7 @@ } #else if (Flt_Rounds == 0) - aadj1 += 0.5; + dval(aadj1) += 0.5; #endif /*Check_FLT_ROUNDS*/ } y = word0(rv) & Exp_mask; @@ -2841,7 +2849,7 @@ if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { dval(rv0) = dval(rv); word0(rv) -= P*Exp_msk1; - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(dval(rv)); dval(rv) += adj; if ((word0(rv) & Exp_mask) >= Exp_msk1*(DBL_MAX_EXP+Bias-P)) { @@ -2861,11 +2869,11 @@ if ((z = aadj) <= 0) z = 1; aadj = z; - aadj1 = dsign ? aadj : -aadj; + dval(aadj1) = dsign ? aadj : -aadj; } word0(aadj1) += (2*P+1)*Exp_msk1 - y; } - adj = aadj1 * ulp(dval(rv)); + adj = dval(aadj1) * ulp(dval(rv)); dval(rv) += adj; #else #ifdef Sudden_Underflow @@ -3178,7 +3186,7 @@ */ char * -dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) +dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve) { /* Arguments ndigits, decpt, sign are similar to those of ecvt and fcvt; trailing zeros are suppressed from @@ -3223,7 +3231,8 @@ ULong x; #endif Bigint *b, *b1, *delta, *mlo = 0, *mhi = 0, *S; - double d2, ds, eps; + double ds; + double_u d, d2, eps; char *s, *s0; #ifdef Honor_FLT_ROUNDS int rounding; @@ -3232,6 +3241,8 @@ int inexact, oldinexact; #endif + dval(d) = d_; + #ifndef MULTIPLE_THREADS if (dtoa_result) { freedtoa(dtoa_result); Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 23352) +++ ruby_1_8/ChangeLog (revision 23353) @@ -1,3 +1,8 @@ +Thu May 7 01:59:35 2009 Tanaka Akira <akr@f...> + + * util.c: suppress strict-aliasing warning with gcc-4.4.0 -O2 to fix + infinite loop by ruby -e "1.402e-45" . + Wed May 6 09:27:04 2009 Nobuyoshi Nakada <nobu@r...> * README.ja: code for THINK_C does not exist already. [Bug #1435] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/