Tested on x86_64-*-freebsd.  OK to commit?

The error message says it all.

2019-10-05  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/91801
        * simplify.c (gfc_simplify_reshape): Convert a gcc_assert into a
        gfc_error as a user can easily hit the condition.

2019-10-05  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/91801
        * gfortran.dg/pr91801.f90: New test.

-- 
Steve
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 276628)
+++ gcc/fortran/simplify.c	(working copy)
@@ -6762,7 +6762,15 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shap
 
 	  gfc_extract_int (e, &order[i]);
 
-	  gcc_assert (order[i] >= 1 && order[i] <= rank);
+	  if (order[i] < 1 || order[i] > rank)
+	    {
+	      gfc_error ("Element with a value of %d in ORDER at %L must be "
+			 "in the range [1, ..., %d] for the RESHAPE intrinsic "
+			 "near %L", order[i], &order_exp->where, rank,
+			 &shape_exp->where);
+	      return &gfc_bad_expr;
+	    }
+
 	  order[i]--;
 	  if (x[order[i]] != 0)
 	    {
Index: gcc/testsuite/gfortran.dg/pr91801.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91801.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91801.f90	(working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/91801
+! Code contributed by Gerhard Steinmetz
+program p
+   integer, parameter :: a(2) = [2,0]              ! { dg-error "Element with a value of" }
+   print *, reshape([1,2,3,4,5,6], [2,3], order=a) ! { dg-error "for the RESHAPE intrinsic near" }
+end

Reply via email to