$ cat reshape-complex.f90
program main
  complex, dimension(8) :: b
  complex, dimension(2,2) :: a
  integer :: i
  b = (/(i,i=1,8)/)
  a = reshape(b(1:8:2),shape(a))
  print *,a
end
$ gfortran -fdump-tree-original reshape-complex.f90
$ ./a.out
 (  1.000000    ,  2.000000    ) (  3.000000    ,  4.000000    ) (
1.4012985E-45,  2.476204    ) ( -1.999693    , 3.9988187E-34)

The problem is that we use

    atmp.5.dtype = 546;
    atmp.5.dim[0].stride = 1;
    atmp.5.dim[0].lbound = 0;
    atmp.5.dim[0].ubound = 1;
    atmp.5.dim[1].stride = 2;
    atmp.5.dim[1].lbound = 0;
    atmp.5.dim[1].ubound = 1;
    atmp.5.data = (complex4[0:] *) &A.6;
    atmp.5.offset = 0;

... 

    _gfortran_reshape_4 (&atmp.5, &parm.7, &atmp.11, 0B, 0B);

which is clearly wrong, because we treat the complex array like
a real array of the same shape.

We need a reshape_c4 and reshape_c8, which needs to be called
correctly from the front end.

-- 
           Summary: reshape of complex broken
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to