While playing with -Warray-temporaries, I noticed that the warning is emitted
twice for RESHAPE as illustrated by the following example:

[macbook] f90/bug% cat pr36928_red.f90
! { dg-do compile }
! { dg-options "-Warray-temporaries" }
! PR 36928 - optimize array interleaving array temporaries
program main
  integer :: i, m, n
  real, dimension(4,5) :: b
  real, dimension(5,4) :: c
  b = reshape([(i, i=1,20)],[4,5])
  m = 5
  n = 4
  c = reshape(b, [m,n])
end program main
[macbook] f90/bug% gfc -Warray-temporaries pr36928_red.f90
pr36928_red.f90:11.17:

  c = reshape(b, [m,n])
                 1
Warning: Creating array temporary at (1)
pr36928_red.f90:11.17:

  c = reshape(b, [m,n])
                 1
Warning: Creating array temporary at (1)

(see the polyhedron test capacita.f90 for "real life" code). If I read
correctly the dump

...
      atmp.3.dtype = 265;
      atmp.3.dim[0].stride = 1;
      atmp.3.dim[0].lbound = 0;
      atmp.3.dim[0].ubound = 1;
      atmp.3.data = (void * restrict) &A.4;
      atmp.3.offset = 0;
      (*(integer(kind=4)[2] * restrict) atmp.3.data)[0] = m;
      (*(integer(kind=4)[2] * restrict) atmp.3.data)[1] = n;
      atmp.6.dtype = 521;
      atmp.6.dim[0].stride = 1;
      atmp.6.dim[0].lbound = 0;
      atmp.6.dim[0].ubound = 1;
      atmp.6.data = (void * restrict) &A.7;
      atmp.6.offset = 0;
      {
        integer(kind=8) S.8;

        S.8 = 0;
        while (1)
          {
            if (S.8 > 1) goto L.1;
            (*(integer(kind=8)[2] * restrict) atmp.6.data)[S.8] =
(integer(kind=8)) (*(integer(kind=4)[2] * restrict) atmp.3.data)[S.8];
            S.8 = S.8 + 1;
          }
        L.1:;
      }
      _gfortran_reshape_r4 (&parm.1, &parm.2, &atmp.6, 0B, 0B);
    }
  }
}

there are two temporaries atmp.3 and atmp.6, and I don't see any reason why the
second one should be needed (all the arguments are INTENT(IN), isn't it?).


-- 
           Summary: Useless temporary with RESHAPE
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr


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

Reply via email to