From 93d1ab50c5a8843e7d6779d4f6956241f8444e50 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Fri, 16 Mar 2018 02:43:02 +0000 Subject: [PATCH] re PR fortran/69395 (ICE on declaring array with more than 7 dimensions+codimensions) 2018-03-15 Steven G. Kargl PR fortran/69395 * decl.c (merge_array_spec): Limit the merging to maximum allowed dimensions, and issue error message if limit is exceeded. 2018-03-15 Steven G. Kargl PR fortran/69395 * gfortran.dg/pr69395.f90: New test. From-SVN: r258580 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/decl.c | 34 +++++++++++++++++++++------ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/pr69395.f90 | 5 ++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr69395.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 19854f1f574..6e1af909a5a 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-03-15 Steven G. Kargl + + PR fortran/69395 + * decl.c (merge_array_spec): Limit the merging to maximum allowed + dimensions, and issue error message if limit is exceeded. + 2018-03-13 Steven G. Kargl * check.c (gfc_check_kill_sub): Remove check for INTEGER(4) or (8). diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 160964399fc..f5e6b31557c 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -804,7 +804,7 @@ cleanup: static bool merge_array_spec (gfc_array_spec *from, gfc_array_spec *to, bool copy) { - int i; + int i, j; if ((from->type == AS_ASSUMED_RANK && to->corank) || (to->type == AS_ASSUMED_RANK && from->corank)) @@ -822,8 +822,14 @@ merge_array_spec (gfc_array_spec *from, gfc_array_spec *to, bool copy) for (i = 0; i < to->corank; i++) { - to->lower[from->rank + i] = to->lower[i]; - to->upper[from->rank + i] = to->upper[i]; + /* Do not exceed the limits on lower[] and upper[]. gfortran + cleans up elsewhere. */ + j = from->rank + i; + if (j >= GFC_MAX_DIMENSIONS) + break; + + to->lower[j] = to->lower[i]; + to->upper[j] = to->upper[i]; } for (i = 0; i < from->rank; i++) { @@ -846,19 +852,33 @@ merge_array_spec (gfc_array_spec *from, gfc_array_spec *to, bool copy) for (i = 0; i < from->corank; i++) { + /* Do not exceed the limits on lower[] and upper[]. gfortran + cleans up elsewhere. */ + j = to->rank + i; + if (j >= GFC_MAX_DIMENSIONS) + break; + if (copy) { - to->lower[to->rank + i] = gfc_copy_expr (from->lower[i]); - to->upper[to->rank + i] = gfc_copy_expr (from->upper[i]); + to->lower[j] = gfc_copy_expr (from->lower[i]); + to->upper[j] = gfc_copy_expr (from->upper[i]); } else { - to->lower[to->rank + i] = from->lower[i]; - to->upper[to->rank + i] = from->upper[i]; + to->lower[j] = from->lower[i]; + to->upper[j] = from->upper[i]; } } } + if (to->rank + to->corank >= GFC_MAX_DIMENSIONS) + { + gfc_error ("Sum of array rank %d and corank %d at %C exceeds maximum " + "allowed dimensions of %d", + to->rank, to->corank, GFC_MAX_DIMENSIONS); + to->corank = GFC_MAX_DIMENSIONS - to->rank; + return false; + } return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ca6618f2b72..9db78cd5d12 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-15 Steven G. Kargl + + PR fortran/69395 + * gfortran.dg/pr69395.f90: New test. + 2018-03-15 Jakub Jelinek PR c++/79085 diff --git a/gcc/testsuite/gfortran.dg/pr69395.f90 b/gcc/testsuite/gfortran.dg/pr69395.f90 new file mode 100644 index 00000000000..ea98baacb29 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr69395.f90 @@ -0,0 +1,5 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +program p +real, dimension(1,2,1,2,1,2,1,2), codimension[1,2,1,2,1,2,1,*] :: z ! { dg-error "allowed dimensions" } +end -- 2.30.2