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



             Bug #: 55072

           Summary: [4.5/4.6/4.7/4.8 Regression] Missing internal_pack

                    leads to wrong code with derived type

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Keywords: wrong-code

          Severity: normal

          Priority: P3

         Component: fortran

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: bur...@gcc.gnu.org





The following code should print (and does so with GCC 4.1, 4.3 and 4.4):

           1           9           3          11

           1           9           3          11

However, starting from GCC 4.5, it prints:

           1           9           3          11

           1           5           9          13



The reason is that the passed pointer is not packed but directly passed (with

array descriptor, which is not used):



  bar ((struct t[0:] *) p.data);



while gfortran 4.4 correctly uses:



    D.1575 = _gfortran_internal_pack (&p);

    bar (D.1575);





implicit none

type t

integer :: i

end type t

type(t), target :: tgt(4,4)

type(t), pointer :: p(:,:)

integer :: i,j,k



k = 1

do i = 1, 4

  do j = 1, 4

    tgt(i,j)%i = k

    k = k+1

  end do

end do



p => tgt(::2,::2)

print *,p%i

call bar(p)



contains



  subroutine bar(x)

    type(t) :: x(*)

    print *,x(1:4)%i

    if (any (x(1:4)%i /= [1, 9, 3, 11])) call abort()

  end subroutine

end

Reply via email to