gcc/fortran/ChangeLog:
PR fortran/103610
* array.c (spec_dimen_size): Fix simplification of SHAPE:
dimensions must be non-negative.
gcc/testsuite/ChangeLog:
PR fortran/103610
* gfortran.dg/shape_11.f90: New test.
(cherry picked from commit
5f7cdea34e118776d0ccd2ff3dda0f5acab18a94)
/********* Subroutines for determining the size of an array *********/
/* These are needed just to accommodate RESHAPE(). There are no
- diagnostics here, we just return a negative number if something
- goes wrong. */
+ diagnostics here, we just return false if something goes wrong. */
/* Get the size of single dimension of an array specification. The
mpz_add_ui (*result, *result, 1);
+ if (mpz_cmp_si (*result, 0) < 0)
+ mpz_set_si (*result, 0);
+
return true;
}
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! PR fortran/103610 - ICE while simplifying SHAPE
+! Contributed by G.Steinmetz
+
+program p
+ integer, parameter :: a(-1) = 1
+ integer, parameter :: b(1) = maskl(shape(a))
+ integer, parameter :: c(1) = shape(a)
+ integer, parameter :: d(1) = maskr(shape(a))
+ if (b(1) /= 0) stop 1
+ if (c(1) /= 0) stop 2
+ if (d(1) /= 0) stop 3
+end
+
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }