In convert_mpz_to_unsigned, an assert was triggered when a positive
argument larger than HUGE() of the respective kind was passed while
-fno-range-check was specified.  The assert should be consistently
skipped in this case.

Regtested on x86_64-pc-linux-gnu.

OK for trunk / 9 / 8?

Thanks,
Harald

2019-11-24  Harald Anlauf  <anl...@gmx.de>

        PR fortran/92629
        * simplify.c (convert_mpz_to_unsigned): Skip assert for argument
        range when -fno-range-check is specified.


2019-11-24  Harald Anlauf  <anl...@gmx.de>

        PR fortran/92629
        * gfortran.dg/pr92629.f90: New testcase.
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c      (Revision 278629)
+++ gcc/fortran/simplify.c      (Arbeitskopie)
@@ -169,8 +169,10 @@ convert_mpz_to_unsigned (mpz_t x, int bitsize)
     }
   else
     {
-      /* Confirm that no bits above the signed range are set.  */
-      gcc_assert (mpz_scan1 (x, bitsize-1) == ULONG_MAX);
+      /* Confirm that no bits above the signed range are set if we
+        are doing range checking.  */
+      if (flag_range_check != 0)
+       gcc_assert (mpz_scan1 (x, bitsize-1) == ULONG_MAX);
     }
 }

Index: gcc/testsuite/gfortran.dg/pr92629.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr92629.f90       (nicht existent)
+++ gcc/testsuite/gfortran.dg/pr92629.f90       (Arbeitskopie)
@@ -0,0 +1,11 @@
+! { dg-do run }
+! { dg-options "-fno-range-check" }
+!
+! Test the fix for PR92629.
+program bge_tests
+  if (bge (huge (1_1), 128_1)) stop 1
+  if (bge (    128_1 , 255_1)) stop 2
+  if (bge (huge (1_2), 32768_2)) stop 3
+  if (bge (huge (1_4), 2147483648_4)) stop 4
+  if (bge (huge (1_8), 9223372036854775808_8)) stop 5
+end program

Reply via email to