[PATCH] PR fortran/69395 -- don't exceed max allowed array dimensions

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Mar 16 14:49:00 GMT 2018


On Fri, Mar 16, 2018 at 11:46:24AM +0100, Dominique d'Humières wrote:
> 
> With one of my variants I see
> 
> pr69395_3_db.f90:2:63:
> 
>     real, dimension(1,2,1,2,1,2,1,2), codimension[1,2,1,2,1,2,*] :: z
>                                                                1
> Error: Sum of array rank 8 and corank 7 at (1) exceeds maximum allowed dimensions of 15
> 
> Is this expected or should
> 
> 	  if (j >= GFC_MAX_DIMENSIONS)
> 
> be replaced with
> 
> 	  if (j > GFC_MAX_DIMENSIONS)
> 
> (twice)?
> 

Well, the above is legal, so there is probably an off-by-one
issue.  Note, that there are a few other places where
"rank + corank >= GFC_MAX_DIMENSIONS" checks are done.
I simply copied a nearby if ().

      array.c:  if (as->rank + as->corank >= GFC_MAX_DIMENSIONS)
      array.c:  if (as->rank >= GFC_MAX_DIMENSIONS)
      array.c:  if (as->rank + as->corank >= GFC_MAX_DIMENSIONS)
      check.c:  if (source->rank >= GFC_MAX_DIMENSIONS)
mine  decl.c:   if (j >= GFC_MAX_DIMENSIONS)
mine  decl.c:   if (j >= GFC_MAX_DIMENSIONS)
      decl.c:   if (to->rank + to->corank >= GFC_MAX_DIMENSIONS)

My checks are breaking out of existing for-loops and protecting
against 

    as->lower[j] = ....
    as->upper[j] = ....

where

gfortran.h:  struct gfc_expr *lower[GFC_MAX_DIMENSIONS], *upper[GFC_MAX_DIMENSIONS];

I'll take a look at the code tomorrow.


-- 
Steve



More information about the Fortran mailing list