Bug 34759 - Assumed size array reference not allowed in SHAPE intrinsic, even though last subscript specified
Assumed size array reference not allowed in SHAPE intrinsic, even though last...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: ---
Assigned To: Tobias Burnus
: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-01-12 20:15 UTC by Dick Hendrickson
Modified: 2008-01-13 21:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-12 22:28:20


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2008-01-12 20:15:59 UTC
With gfortran 4.3.0 20080109 I get an incorrect error message
"Error: 'source' argument of 'shape' intrinsic at (1) must not
be an assumed size array" with the following little test case

       subroutine j_assumed_size(A,N)
       dimension A(10,11,12,*)
       k = shape(A(:,:,:,N))
       l = shape(A(:,:,:,3))
       end

I believe assumed size arrays are allowed provided the last subscript
is specified.

Dick Hendrickson
Comment 1 Tobias Burnus 2008-01-12 21:13:54 UTC
Confirm, though your reduced test case is invalid (the variables k and l need to be arrays. Corrected test case:

       subroutine j_assumed_size(A,N)
       dimension A(10,11,12,*), k(3), l(3)
       k = shape(A(:,:,:,N))
       l = shape(A(:,:,:,3))
       end

"SOURCE may be of any type. It may be a scalar or an array. It shall not be an
unallocated allocatable or a pointer that is not associated. It shall not be an
assumed-size array."

The shall-nots do not apply for the rank-3 arrays A(:,:,:,N) and A(:,:,:,3). Actually, this could be a wider problem, which is not only limited to check.c's gfc_check_shape. (For actual/dummy argument checking, I added a note to PR 34665.)

Thanks for the report.
Comment 2 Tobias Burnus 2008-01-12 22:28:20 UTC
Patch. I think this is the only place to change, interface's compare_actual_formal is actually ok.

Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c (revision 131492)
+++ gcc/fortran/check.c (working copy)
@@ -2394,7 +2394,7 @@ gfc_check_shape (gfc_expr *source)

   ar = gfc_find_array_ref (source);

-  if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
+  if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
     {
       gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
                 "an assumed size array", &source->where);
Comment 3 Tobias Burnus 2008-01-13 17:41:52 UTC
Patch: http://gcc.gnu.org/ml/gcc-patches/2008-01/msg00566.html
Comment 4 Tobias Burnus 2008-01-13 21:29:14 UTC
Subject: Bug 34759

Author: burnus
Date: Sun Jan 13 21:28:30 2008
New Revision: 131511

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131511
Log:
2008-01-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34759
        * check.c (gfc_check_shape): Accept array ranges of
        assumed-size arrays.

2008-01-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34759
        * gfortran.dg/assumed_size_refs_4.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/assumed_size_refs_4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Tobias Burnus 2008-01-13 21:49:05 UTC
Fixed on the trunk (4.3.0).

Thanks for the report!