Bug 21108 - [4.0 only] reshape with order causes random results
Summary: [4.0 only] reshape with order causes random results
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-19 20:09 UTC by Thomas Koenig
Modified: 2005-05-21 20:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail: 4.0.1
Last reconfirmed: 2005-04-29 11:02:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2005-04-19 20:09:27 UTC
... 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.
Comment 1 Tobias Schlüter 2005-04-22 13:21:20 UTC
I think you copy/pasted the wrong "working" testcase.
Comment 2 GCC Commits 2005-04-22 20:02:53 UTC
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

Comment 3 Thomas Koenig 2005-04-23 18:09:54 UTC
> 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)
Comment 4 GCC Commits 2005-05-21 19:57:01 UTC
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

Comment 5 Thomas Koenig 2005-05-21 20:30:41 UTC
Fixed in 4.0.
Comment 6 GCC Commits 2005-07-30 22:29:34 UTC
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