Bug 57285 - [OOP] ICE on invalid: "gfc_array_dimen_size(): Bad dimension" due to SIZE intrinsic with invalid dim on CLASS dummy
Summary: [OOP] ICE on invalid: "gfc_array_dimen_size(): Bad dimension" due to SIZE int...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2013-05-15 10:18 UTC by Lorenz Hüdepohl
Modified: 2016-11-16 15:38 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-15 00:00:00


Attachments
Minimal test case (135 bytes, text/x-fortran)
2013-05-15 10:18 UTC, Lorenz Hüdepohl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lorenz Hüdepohl 2013-05-15 10:18:06 UTC
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.
Comment 1 Lorenz Hüdepohl 2013-05-15 10:18:46 UTC
Created attachment 30120 [details]
Minimal test case
Comment 2 janus 2013-05-15 14:09:25 UTC
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!)
Comment 3 janus 2013-07-27 09:07:05 UTC
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;
Comment 4 janus 2013-07-27 10:08:12 UTC
(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 ...
Comment 5 janus 2013-07-27 13:09:07 UTC
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
Comment 6 Mikael Morin 2013-07-27 13:47:57 UTC
(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?