Follow up to PR 43173 - but this time for derived types. In the following calls, if the ultimate component is a non-pointer and all previous part-refs have no vector subscripts, there is no need for packing the argument (i.e. creating a temporary).
However, if the ultimate component is a pointer, one needs to pack as the test case also shows. Correctness test fails with 4.5.0 20100218 (experimental) [trunk revision 156860] 4.5.0 20100303 (experimental) but works with 4.4.2 [gcc-4_4-branch revision 155966] 4.3.4 [gcc-4_3-branch revision 152973] module m type t integer, allocatable :: a(:) integer, pointer :: b(:) integer :: c(5) end type t end module m subroutine foo(a,d,e,n) use m implicit none integer :: n type(t) :: a type(t), allocatable :: d(:) type(t), pointer :: e(:) call bar( a%a) ! OK - no array temp needed call bar( a%c) ! OK - no array temp needed call bar( a%a(1:n)) ! Missed: No pack needed call bar( a%b(1:n)) ! OK: pack needed call bar( a%c(1:n)) ! Missed: No pack needed call bar(d(1)%a(1:n)) ! Missed: No pack needed call bar(d(1)%b(1:n)) ! OK: pack needed call bar(d(1)%c(1:n)) ! Missed: No pack needed call bar(e(1)%a(1:n)) ! Missed: No pack needed call bar(e(1)%b(1:n)) ! OK: pack needed call bar(e(1)%c(1:n)) ! Missed: No pack needed end subroutine foo use m implicit none integer :: i integer, target :: z(6) type(t) :: y z = [(i, i=1,6)] y%b => z(::2) call bar(y%b) end subroutine bar(x) integer :: x(1:*) print *, x(1:3) if (any (x(1:3) /= [1,3,5])) call abort () end subroutine bar -- Summary: [4.5 Regression] Missing array temp for DT with pointer component Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: wrong-code, missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org OtherBugsDependingO 42361 nThis: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43243