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

--- Comment #6 from Harald Anlauf <anlauf at gmx dot de> ---
Another testcase suitable for debugging is the following, which better
shows correspondence for pre-F2008 and F2008+ variants:

program test
  implicit none
  integer, pointer :: t(:), u(:)
  integer          :: i
  allocate (t(-1:5))
  do i = -1, 5
     t(i) = i
  end do
  call p (t     )  ! Pointer with lower bound = -1 from allocation
  u     => t       ! Pointer assignment sets same lower bound
  call p (u)
  !
  u     => t( :)   ! Pointer assignment with implicit lower bound (1)
  call p (u)
  call p (t(  :))  ! Full array, behaves the same
  !
  call p (t( 0:))  ! Array section
  u     => t(0:)   ! Pointer assignment with implicit lower bound (1)
  call p (u)
  u(0:) => t(0:)   ! Pointer assignment with given lower bound (0)
  call p (u)
contains
  subroutine p (a)
    integer, pointer, intent(in) :: a(:)
    print *, a(1)
  end subroutine p
end program

NAG and Crayftn both print the supposedly correct result:

 1
 1
 -1
 -1
 0
 0
 1

Current 9-trunk:

           1
           1
          -1
           1
           2
           0
           1

gcc-8.2.1:

           1
           1
          -1
           1
           0
           0
           1

gcc-7.3.1, 6.x, 5.x, 4.6:

           1
           1
          -1
           1
           1
           0
           1

gcc-4.9, 4.8:

           1
           1
          -1
           1
           1
           0
           0

So it is a varying sort of wrong code issue...
Only output lines 1,2,3 and 6 are always correct.

Reply via email to