public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34788]  New: Error diagnostic issued passing array element to explicit shape dummy argument
@ 2008-01-15  8:57 refson dot temp at ntlworld dot com
  2008-01-15 20:34 ` [Bug fortran/34788] " burnus at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: refson dot temp at ntlworld dot com @ 2008-01-15  8:57 UTC (permalink / raw)
  To: gcc-bugs

Gfortran version 4.3.0 20080114 (experimental) [trunk revision 131520]
issues a diagnostic

   call b(z(1))
         1
Error: Element of assumed-shaped array passed to dummy argument 'x' at (1)

on the attached program.  This diagnostic is (a) misleading - b is NOT
an assumed-shape array, and (b) incorrect.  I believe the code is
standard conforming Fortran under the provision allowing an array
element to be passed to an array dummy argument.

Gfortran 4.3.0 20071126 (experimental) [trunk revision 130431] compiles
the code without any diagnostic, as do the NAG, g95, ifort, IBM XLF, pathscale,
pgi compilers.

module passtest
integer, dimension(:),allocatable,save :: z
integer, dimension(4) :: t
contains
 subroutine a
   call b(z(1))
   call b(t(1))
 end subroutine a
 subroutine b(x)
   integer, dimension(2) :: x
 end subroutine b
end module passtest


-- 
           Summary: Error diagnostic issued passing array element to
                    explicit shape dummy argument
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: refson dot temp at ntlworld dot com
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34788


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/34788] Error diagnostic issued passing array element to explicit shape dummy argument
  2008-01-15  8:57 [Bug fortran/34788] New: Error diagnostic issued passing array element to explicit shape dummy argument refson dot temp at ntlworld dot com
@ 2008-01-15 20:34 ` burnus at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-01-15 20:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-01-15 19:30 -------
Confirmed. Your bugreport was there even before mine, but since my contains a
link to the patch I mark yours as duplicate.

Thanks for finding the bug.

> This diagnostic is (a) misleading - b is NOT an assumed-shape array,
> and (b) incorrect.  I believe the code is standard conforming Fortran
> under the provision allowing an array element to be passed to an array
> dummy argument.

(a) is true: It is an array of deferred shape and thus the error message is
indeed wrong. (Both from the message and from showing an error message at all.)

Otherwise the error message is correct: You may not pass an element of an
assumed-shape array (or a pointer) to an assumed-shape dummy argument.

The reason is that there is no reason for such arrays to be contiguous in
memory.

Assume for instance:

subroutine func(a)
  integer :: a(:)
  call func2(a(4))
contains
  subroutine func2(b)
    integer :: b(5) ! or "integer :: b(*)"
  end subroutine func2
end subroutine func

If one now calls "func" as "call func(array(1:100:20))", the array A is not
contiguous in memory because of the strides.

Passing "A(4)" now to func2 poses a problem: b(2) is outside of the array "A"
(though within array "array").

In order to prevent this problem, the standard does not allow to pass elements
of assumed-shaped arrays or pointers as actual argument to array dummy
arguments.

The bug is only that my patch accidentally also rejected arrays with deferred
shape (as your example); since here the allocation is in the same subroutine as
the call, the memory is contiguous and there is no problem.

(In principle, the array "A" could be copied into a temporary array with no
strides, but this is not what the standard mandates here. If one calls "func2"
as "call func2(a(11:15))" this is actually done so - if "A" has strides.)

*** This bug has been marked as a duplicate of 34796 ***


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34788


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-01-15 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15  8:57 [Bug fortran/34788] New: Error diagnostic issued passing array element to explicit shape dummy argument refson dot temp at ntlworld dot com
2008-01-15 20:34 ` [Bug fortran/34788] " burnus at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).