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

            Bug ID: 93956
           Summary: Wrong array creation with p => array_dt(1:n)%component
           Product: gcc
           Version: 9.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mscfd at gmx dot net
  Target Milestone: ---

The following code (compiled without any options) prints "15000, 10000" for the
second call to foo, instead of the expected "20000, 10000". The first call to
foo gives the expected result. This is also reproducible with gfortran-10
branch.

This code is a variation of the one reported in bug 93918 to further understand
temporary array creation.

program array_temps
implicit none

type :: tt
   integer :: u = 1
   integer :: v = 2
end type tt

type(tt), dimension(:), pointer :: r
integer :: n
integer, dimension(:), pointer :: p

allocate(r(1:n))
call foo(r(:)%v, n)
p => get(r(:))
call foo(p, n)
deallocate(r)

contains

   subroutine foo(a, n)
      integer, dimension(:), intent(in) :: a
      integer, intent(in) :: n
      print *, sum(a(1:n)), n
   end subroutine foo

   function get(x) result(q)
      type(tt), dimension(:), target, intent(in) :: x
      integer, dimension(:), pointer :: q
      q => x(:)%v
   end function get

end program array_temps

Reply via email to