The Go frontend recently started checking whether an exponent was out
of range when parsing a string into a floating point number.  It turns
out that in GCC the mpfr exponent range is target dependent, due to PR
88074.  That breaks some Go programs that use large exponents in
untyped constants on processors with limited floating point exponent
range, like ARM (those Go programs were always compiled incorrectly,
but now we at least report an error when that happens).  This patch
changes the Go frontend to force the mpfr exponent range to be large
enough for Go code, although in some cases that may cause the
middle-end to compile code slowly.  This should fix PR 98402.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

PR go/98402
* go-lang.c (go_langhook_init): Force MPFR exponent range to be
large enough to support Go constants.
diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c
index 08c1f38a2c1..9c0e7af7b84 100644
--- a/gcc/go/go-lang.c
+++ b/gcc/go/go-lang.c
@@ -131,6 +131,16 @@ go_langhook_init (void)
      eventually be controllable by a command line option.  */
   mpfr_set_default_prec (256);
 
+  /* If necessary, override GCC's choice of minimum and maximum
+     exponents.  This should only affect GCC middle-end
+     compilation-time, not correctness.  */
+  mpfr_exp_t exp = mpfr_get_emax ();
+  if (exp < (1 << 16) - 1)
+    mpfr_set_emax ((1 << 16) - 1);
+  exp = mpfr_get_emin ();
+  if (exp > - ((1 << 16) - 1))
+    mpfr_set_emin (- ((1 << 16) - 1));
+
   /* Go uses exceptions.  */
   using_eh_for_cleanups ();
 

Reply via email to