The following invalid code produces an internal error. It is invalid as it uses size() with a dim argument of 2 that is larger than the number of dimensions of the referred array. > cat minimal.f90 module testmod type type_t integer :: dummy end type type_t contains subroutine foo(a) class(type_t), intent(in) :: a(:) type(type_t) :: c(size(a,dim=2)) end subroutine end module testmod > > ~/sys/bin/gfortran minimal.f90 minimal.f90:10.18: end module testmod 1 Internal Error at (1): gfc_array_dimen_size(): Bad dimension > > ~/sys/bin/gfortran --version GNU Fortran (GCC) 4.9.0 20130514 (experimental) Copyright (C) 2013 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING Here, ~/sys/bin/gfortran is a self-compiled gfortran from yesterday's trunk, the ICE also happens with the gfortran 4.7.2 supplied with openSUSE: > gfortran --version GNU Fortran (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012] Copyright (C) 2012 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING > gfortran minimal.f90 minimal.f90:10.18: end module testmod 1 Internal Error at (1): gfc_array_dimen_size(): Bad dimension This might be related to Bug #57284.
Created attachment 30120 [details] Minimal test case
Confirmed. Changing "a" from CLASS to TYPE ... type type_t end type contains subroutine foo(a) type(type_t), intent(in) :: a(:) type(type_t) :: c(size(a,dim=2)) end subroutine end ... one gets the correct error message: type(type_t) :: c(size(a,dim=2)) 1 Error: 'dim' argument of 'size' intrinsic at (1) is not a valid dimension index (unfortunately twice!)
Why the hell do we disable the dimension check for CLASS variables? Index: gcc/fortran/check.c =================================================================== --- gcc/fortran/check.c (revision 201253) +++ gcc/fortran/check.c (working copy) @@ -608,9 +608,6 @@ dim_rank_check (gfc_expr *dim, gfc_expr *array, in if (dim->expr_type != EXPR_CONSTANT) return true; - if (array->ts.type == BT_CLASS) - return true; - if (array->expr_type == EXPR_FUNCTION && array->value.function.isym && array->value.function.isym->id == GFC_ISYM_SPREAD) rank = array->rank + 1;
(In reply to janus from comment #3) > Why the hell do we disable the dimension check for CLASS variables? Seems to be some sort of artifact from the early class-array implementation: http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=182210 > Index: gcc/fortran/check.c > =================================================================== > --- gcc/fortran/check.c (revision 201253) > +++ gcc/fortran/check.c (working copy) > @@ -608,9 +608,6 @@ dim_rank_check (gfc_expr *dim, gfc_expr *array, in > if (dim->expr_type != EXPR_CONSTANT) > return true; > > - if (array->ts.type == BT_CLASS) > - return true; > - > if (array->expr_type == EXPR_FUNCTION && array->value.function.isym > && array->value.function.isym->id == GFC_ISYM_SPREAD) > rank = array->rank + 1; In any case, this patch regtests cleanly. Will commit as obvious ...
Fixed with the commit below. Closing. Thanks for the report! Author: janus Date: Sat Jul 27 12:55:59 2013 New Revision: 201284 URL: http://gcc.gnu.org/viewcvs?rev=201284&root=gcc&view=rev Log: 2013-07-27 Janus Weil <janus@gcc.gnu.org> PR fortran/57285 * check.c (dim_rank_check): Re-enable this check for CLASS arrays. 2013-07-27 Janus Weil <janus@gcc.gnu.org> PR fortran/57285 * gfortran.dg/class_array_19.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/class_array_19.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/testsuite/ChangeLog
(In reply to janus from comment #4) > (In reply to janus from comment #3) > > Why the hell do we disable the dimension check for CLASS variables? > > Seems to be some sort of artifact from the early class-array implementation: > > http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=182210 > Maybe there are other "sort of artifact" to remove?