This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[fortran,patch] Call mpfr_check_range after setting emin/emax


For a few months now, I've seen a failure of gfortran.dg/ nearest_4.f90 on my x86_64-linux build machine; the fact that noone else saw it, I suppose, is because I use GMP and MPFR built with internal checking (assertions) enabled. The following patch fixes it:

Index: simplify.c
===================================================================
--- simplify.c  (revision 134839)
+++ simplify.c  (working copy)
@@ -2821,6 +2821,7 @@ gfc_simplify_nearest (gfc_expr *x, gfc_e
   mpfr_set_emin ((mp_exp_t) gfc_real_kinds[kind].min_exponent -
                mpfr_get_prec(result->value.real) + 1);
   mpfr_set_emax ((mp_exp_t) gfc_real_kinds[kind].max_exponent - 1);
+  mpfr_check_range (result->value.real, 0, GMP_RNDU);

   if (mpfr_sgn (s->value.real) > 0)
     {


It follows the MPFR doc, which says that it's our responsability to make sure a real number is still in range after we've used mpfr_set_e {min,max}. These functions are used in another place in arith.c, which I propose to also fix:


Index: arith.c
===================================================================
--- arith.c (revision 134839)
+++ arith.c (working copy)
@@ -384,6 +384,7 @@ gfc_check_real_range (mpfr_t p, int kind
en = gfc_real_kinds[i].min_exponent - gfc_real_kinds [i].digits + 1;
mpfr_set_emin ((mp_exp_t) en);
mpfr_set_emax ((mp_exp_t) gfc_real_kinds[i].max_exponent);
+ mpfr_check_range (q, 0, GFC_RND_MODE);
mpfr_subnormalize (q, 0, GFC_RND_MODE);


/* Reset emin and emax. */


I will regtest and keep you posted, but does someone have an objection on the principle of it, or does it sound like the right fix?


FX


-- François-Xavier Coudert http://www.homepages.ucl.ac.uk/~uccafco/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]