https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119986

            Bug ID: 119986
           Summary: Complex array part references are being passed
                    incorrectly to a procedure
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neil.n.carlson at gmail dot com
  Target Milestone: ---

The follow example outputs incorrect results.

program main
  type :: my_type
    complex, allocatable :: phi(:)
  end type
  integer :: j
  type(my_type) :: x
  x%phi = [(cmplx(j,-j),j=1,4)]
  call fubar(x%phi%re, x%phi%im)
contains
  subroutine fubar(u, v)
    real, intent(in) :: u(:), v(:)
    print *, 'phi%re:', u
    print *, 'phi%im:', v
  end subroutine
end program

The correct results should be

 phi%re:   1.000000       2.000000       3.000000       4.000000    
 phi%im:  -1.000000      -2.000000      -3.000000      -4.000000    

But the gfortran-5.1.0 compiled code outputs

 phi%re:   1.00000000      -1.00000000       2.00000000      -2.00000000    
 phi%im:   1.00000000      -1.00000000       2.00000000      -2.00000000    

The correct real and imaginary part references are not being passed to the
subroutine.
Note that if the complex array is not a component of a derived type, but simply
a local
or dummy array, then the correct part references are passed.

Reply via email to