Bug reported (with longer test case) by Maciej Zwierzycki
  at http://gcc.gnu.org/ml/fortran/2009-06/msg00254.html


The following program should produce  1   2 -42 -42
                      but it produces 1 -42   2 -42

For
  a(1,:) = func()
gfortran decides to pass result value by reference - and uses an array
descriptor for this (why?):
  func (struct array1_integer(kind=4) & __result)
and
  func (&parm.7);

However, as "func(2)" is an explicit-shaped array, it should be contiguous and
thus for "call sub(func)" simply the address is passed, ignoring the stride:

  sub ((integer(kind=4)[0:] *) parm.4.data);

At some place the copy-in/copy-out must happen. Actually, I had assumed that
already the call to "func" would cause a temporary be created. That's actually
what happens in case of g95:
  SC1 = *func_ ();;

Test case:


integer :: a(2,2)
a = -42
a(1,:) = func()
print *,a
contains
 function func()
   integer :: func(2)
   call sub(func)
 end function func
 subroutine sub(a)
   integer :: a(2)
   a = [1,2]
 end subroutine
end


-- 
           Summary: Wrong code due to missing copy-in/copy-out stried array
                    to assumed-size dummy
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org
OtherBugsDependingO 40443
             nThis:


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

Reply via email to