... or so it seems. This doesn't work: $ cat reshape-2.f90 program resh real, dimension (0:1,0:2) :: a,c real, dimension (12) :: b b = (/(i,i=1,12)/) a = reshape(b(1:12:2),shape(a),order=(/2,1/)) print '(6F8.3)',a c = reshape(b(1:12:2),shape(a),order=(/2,1/)) print '(6F8.3)',c end $ gfortran reshape-2.f90 $ ./a.out 0.000 0.000 0.000 2.029 2.027 2.025 -2.000 2.022 0.000 2.166 0.000 0.000 This works: $ cat reshape-2.f90 program resh real, dimension (0:1,0:2) :: a,c real, dimension (12) :: b b = (/(i,i=1,12)/) a = reshape(b(1:12:2),shape(a),order=(/2,1/)) print '(6F8.3)',a c = reshape(b(1:12:2),shape(a),order=(/2,1/)) print '(6F8.3)',c end $ gfortran reshape-2.f90 $ ./a.out 0.000 0.000 0.000 2.029 2.027 2.025 -2.000 2.022 0.000 2.166 0.000 0.000 $ gfortran -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.1/configure --enable-languages=c,f95 --prefix=/home/ig25 Thread model: posix gcc version 4.1.0 20050419 (experimental) Reshape is trickier than I thought, apparently.
I think you copy/pasted the wrong "working" testcase.
Subject: Bug 21108 CVSROOT: /cvs/gcc Module name: gcc Changes by: tkoenig@gcc.gnu.org 2005-04-22 20:02:44 Modified files: gcc/testsuite : ChangeLog libgfortran : ChangeLog libgfortran/generated: reshape_i4.c reshape_i8.c libgfortran/intrinsics: reshape_generic.c libgfortran/m4 : reshape.m4 Added files: gcc/testsuite/gfortran.dg: nested_reshape.f90 reshape-alloc.f90 reshape.f90 Log message: 05-04-22 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * gfortran.dg/nested_reshape.f90: new test * gfortran.dg/reshape-alloc.f90: new test * gfortran.dg/reshape.f90: new test 2005-04-22 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * m4/reshape.m4 (reshape_`'rtype_kind): rs, rex: New variables, to be used in calculation of return array sizes. Populate return array descriptor if ret->data is NULL. Fix condition for early return (it used to test something undefined if order was used). Remove duplicate check wether pad is used. * intrinsics/reshape_generic.c (reshape_generic): Likewise. Fix a few places where the wrong variables were set. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/nested_reshape.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-alloc.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5383&r2=1.5384 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.198&r2=1.199 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i4.c.diff?cvsroot=gcc&r1=1.6&r2=1.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i8.c.diff?cvsroot=gcc&r1=1.6&r2=1.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/intrinsics/reshape_generic.c.diff?cvsroot=gcc&r1=1.7&r2=1.8 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/reshape.m4.diff?cvsroot=gcc&r1=1.7&r2=1.8
> I think you copy/pasted the wrong "working" testcase. Yes, I did :-( Here is a corrected version. $ gfortran reshape-0.f90 $ ./a.out Aborted $ cat reshape-0.f90 ! { dg-do run } ! This tests a few reshape PRs. program resh implicit none real, dimension (2,3) :: a,c real, dimension (12) :: b integer :: i ! PR 21108: This used to give undefined results. b = (/(i,i=1,12)/) a = reshape(b(1:12:2),shape(a),order=(/2,1/)) c = reshape(b(1:12:2),shape(a),order=(/2,1/)) if (any (a /= c)) call abort end $ gfortran -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.0/configure --prefix=/home/ig25 --enable-languages=c,f95 --enable-checking Thread model: posix gcc version 4.0.1 20050423 (prerelease)
Subject: Bug 21108 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tkoenig@gcc.gnu.org 2005-05-21 19:56:44 Modified files: libgfortran/generated: reshape_c4.c reshape_c8.c reshape_i4.c reshape_i8.c libgfortran/intrinsics: reshape_generic.c libgfortran/m4 : reshape.m4 libgfortran : ChangeLog gcc/testsuite : ChangeLog Log message: 005-05-21 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * m4/reshape.m4 (reshape_`'rtype_kind): rs, rex: New variables, to be used in calculation of return array sizes. Populate return array descriptor if ret->data is NULL. Fix condition for early return (it used to test something undefined if order was used). Remove duplicate check wether pad is used. * intrinsics/reshape_generic.c (reshape_generic): Likewise. Fix a few places where the wrong variables were set. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. 2005-05-21 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * gfortran.dg/nested_reshape.f90: new test * gfortran.dg/reshape-alloc.f90: new test * gfortran.dg/reshape.f90: new test Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c8.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5&r2=1.5.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i8.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5&r2=1.5.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/intrinsics/reshape_generic.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.6&r2=1.6.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/reshape.m4.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.6.12.1&r2=1.6.12.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.163.2.35&r2=1.163.2.36 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.192&r2=1.5084.2.193
Fixed in 4.0.
Subject: Bug 21108 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tkoenig@gcc.gnu.org 2005-07-30 22:29:25 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gfortran.dg: nested_reshape.f90 reshape-alloc.f90 reshape.f90 Log message: 2005-07-30 Thomas Koenig <Thomas.Koenig@online.de> Backport from mainline: PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * gfortran.dg/nested_reshape.f90: Actually commit. * gfortran.dg/reshape-alloc.f90: Actually commit. * gfortran.dg/reshape.f90: Actually commit. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.311&r2=1.5084.2.312 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/nested_reshape.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.14.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-alloc.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.14.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.14.1