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

            Bug ID: 84538
           Summary: Array of derived type elements incorrectly accessed in
                    function
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abensonca at gmail dot com
  Target Milestone: ---

The following code results in incorrect behavior with gfortran 8.0.1 (r257956):

module bugMod
  public
  type :: t
     integer :: i
  end type t
  type, extends(t) :: te
     integer :: j
  end type te
contains
  subroutine check(n)
    implicit none
    class(t), intent(inout), dimension(:) :: n
    write (0,*) "FROM MODULE  ",n%i
    return
  end subroutine check
end module bugMod

program bug
  use bugMod
  class(t), allocatable, dimension(:) :: n
  allocate(te :: n(2))
  n(1:2)%i=[8,3]
  write (0,*) "FROM PROGRAM ",n%i
  call check(n)
end program bug

$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/nfs/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/nfs/home/abenson/Galacticus/Tools
--enable-languages=c,c++,fortran --disable-multilib
Thread model: posix
gcc version 8.0.1 20180223 (experimental) (GCC) 

$ gfortran bug.F90
$ a.out 
 FROM PROGRAM            8           3
 FROM MODULE             8           0

I would expect the output to be the same from the module subroutine as from the
main program.

Reply via email to