Bug 36825 - [F08] Rank > 7 arrays [will break library ABI] libgfortran I/O+intrinsics:
Summary: [F08] Rank > 7 arrays [will break library ABI] libgfortran I/O+intrinsics:
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on: 37577
Blocks: F2008 56818 39178 45424
  Show dependency treegraph
Reported: 2008-07-14 17:25 UTC by Tobias Burnus
Modified: 2018-01-30 18:24 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2008-07-28 09:46:31


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-07-14 17:25:45 UTC
gfortran 4.4 allows 15 instead of 7 dimensions, however, it has some problems with that:

gfortran -std=f95 -Wall -pedantic should print a message for:

integer,parameter                        :: N=10
complex,dimension(-N:N,-N:N,0:1,0:1,-N:N,-N:N,0:1,0:1)   :: P

But it does not. This seems to be an off-by-one error as for 9 dimensions an error is printed:
  Error: Fortran 2008: Array specification at (1) with more than 7 dimensions

  * * *

More seriously, adding a PRINT causes an IDE:

a.f90:1: internal compiler error: in gfc_get_dtype, at fortran/trans-types.c:1254

integer,parameter                        :: N=10
complex,dimension(-N:N,-N:N,0:1,0:1,-N:N,-N:N,0:1,0:1)   :: P
print *, p
Comment 1 Tobias Burnus 2008-07-14 17:28:39 UTC
The I/O ICE is due to:
  trans-types.c:  gcc_assert (rank <= GFC_DTYPE_RANK_MASK);
where the maximal DTYPE rank is defined as:
  libgfortran.h:#define GFC_DTYPE_RANK_MASK 0x07

The other problem can be cured using:

Index: array.c
--- array.c     (Revision 137756)
+++ array.c     (Arbeitskopie)
@@ -437,7 +437,7 @@ gfc_match_array_spec (gfc_array_spec **a
          goto cleanup;

-      if (as->rank > 7
+      if (as->rank >= 7
          && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Array "
                             "specification at %C with more than 7 dimensions")
             == FAILURE)
Comment 2 Tobias Burnus 2008-07-16 20:36:45 UTC
Jerry, you know libgfortran better than me. Can one simply change in libgfortran.h:
  #define GFC_DTYPE_RANK_MASK 0x07
to 0x0F  (= 15)  or does this cause some problems with the gcc 4.3 compatibility or ... ? Actually, why is this defined as "0x07" and not as "7"?
Comment 3 Tobias Burnus 2008-07-17 05:55:32 UTC
Subject: Bug 36825

Author: burnus
Date: Thu Jul 17 05:54:42 2008
New Revision: 137910

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137910
2008-07-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36825
        PR fortran/36824
        * array.c (gfc_match_array_spec): Fix array-rank check.
        * resolve.c (resolve_fl_derived): Fix constentness check
        for the array dimensions.

2008-07-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36825
        PR fortran/36824
        * gfortran.dg/rank_2.f90: Add additional array-rank test.
        * gfortran.dg/array_4.f90: New.


Comment 4 Jerry DeLisle 2008-07-19 17:12:34 UTC
Tobias, I just caught up with your question to me today.  I think you have answered it. :)  Thanks for patch.  One thing we should do is check internal unit array I/O with higher dimensions to see if the loop spec code holds up.  I will do that.
Comment 5 Jerry DeLisle 2008-07-21 05:17:44 UTC
Internal unit array I/O with dimensions greater than 7 appears to work OK.
Comment 6 Tobias Burnus 2008-07-27 19:54:25 UTC
See also http://gcc.gnu.org/ml/fortran/2008-07/msg00211.html
Problem is the libgfortran ABI. Email mentions PR 35718, which presumably also means an ABI breakage.
Comment 7 Jerry DeLisle 2008-07-27 23:25:53 UTC
I see only one place in the I/O library that uses GFC_DTYPE_RANK_MASK.

There are many many places in the intrinsics.
Comment 8 Tobias Burnus 2008-07-28 06:41:37 UTC
> I see only one place in the I/O library that uses GFC_DTYPE_RANK_MASK.
> There are many many places in the intrinsics.

Hmm, true. Maybe one should disable the rank 15 in the frontend again. I see GFC_DESCRIPTOR used in:   associated.c, cshift0.c, date_and_time.c, eoshift0.c, eoshift2.c, iso_c_binding.c, move_alloc.c, pack_generic.c, random.c, reshape_generic.c, size.c, spread_generic.c, stat.c, transpose_generic.c, unpack_generic.c, transfer.c, unit.c, in_pack_generic.c, in_unpack_generic.c, cshift1.m4, eoshift1.m4, eoshift3.m4, iforeach.m4, ifunction_logical.m4, ifunction.m4, in_pack.m4, in_unpack.m4, matmull.m4, matmul.m4, pack.m4, reshape.m4, shape.m4, spread.m4, transpose.m4, unpack.m4.
Comment 9 Thomas Koenig 2008-07-28 09:46:31 UTC

Comment 10 Tobias Burnus 2008-08-16 15:54:39 UTC
Subject: Bug 36825

Author: burnus
Date: Sat Aug 16 15:53:14 2008
New Revision: 139152

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139152
2008-08-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36825
        * libgfortran.h: Reduce GFC_MAX_DIMENSIONS to 7.

2008-08-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36825
        * gfortran.dg/rank_1.f90: Modify error message.


Comment 11 Jerry DeLisle 2009-08-15 02:17:49 UTC
Updating summary to reflect the focus of this PR.
Comment 12 Tobias Burnus 2012-09-15 13:09:15 UTC
We also need to update dwarf2out.h, which has:

266struct array_descr_info
268  int ndimensions;
269  tree element_type;
270  tree base_decl;
271  tree data_location;
272  tree allocated;
273  tree associated;
274  struct array_descr_dimen
275    {
276      tree lower_bound;
277      tree upper_bound;
278      tree stride;
279    } dimen[10];

Thus, GCC limits the maximal rank to 10.
Comment 13 Thomas Koenig 2018-01-30 18:24:30 UTC
This is now fixed after Paul's patch for PR 37377.