diff mbox series

PR fortran/91801 -- convert assert to an error

Message ID 20191005162110.GA9763@troutmask.apl.washington.edu
State New
Headers show
Series PR fortran/91801 -- convert assert to an error | expand

Commit Message

Steve Kargl Oct. 5, 2019, 4:21 p.m. UTC
Tested on x86_64-*-freebsd.  OK to commit?

The error message says it all.

2019-10-05  Steven G. Kargl  <kargl@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  <kargl@gcc.gnu.org>

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

Comments

Thomas Koenig Oct. 6, 2019, 7:18 p.m. UTC | #1
Hi Steve,

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

OK.

Thanks a lot for the patch!
diff mbox series

Patch

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