Bug 21480 - [4.0 only] trivial reshape operation gives erroneous results
Summary: [4.0 only] trivial reshape operation gives erroneous results
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Thomas Koenig
URL: http://gcc.gnu.org/ml/fortran/2005-06...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2005-05-09 23:04 UTC by Kamaraju Kusumanchi
Modified: 2005-07-17 19:12 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-06-08 20:20:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kamaraju Kusumanchi 2005-05-09 23:04:05 UTC
$cat reshape_bug.f90
program reshape_bug
 implicit none
 integer, parameter :: NX = 2
 complex :: a(0:NX-1)

 a(:) = cmplx(0.0, 0.0)
 write(*,*) 'before'
 write(*,*) a(:)
 a(0:NX-1) = reshape(a(0:NX-1), (/NX/))
 write(*,*) 'after'
 write(*,*) a(:)
end program reshape_bug

$gfortran-snapshot reshape_bug.f90

$./a.out
 before
 (  0.000000    ,  0.000000    ) (  0.000000    ,  0.000000    )
 after
 (  0.000000    ,  0.000000    ) (  2.022202    ,  0.000000    )

The program changes the value of a(2) once reshape function is executed. But
infact a(2) should just remain as (  0.000000    ,  0.000000    ).

Using debian, sid.
$gfortran-snapshot -v
Using built-in specs.
Target: i486-linux
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang
--prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --disable-nls
--program-suffix=-20050507-1 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug
--enable-java-gc=boehm --enable-java-awt=gtk --enable-mpfr --disable-werror
--disable-werror i486-linux
Thread model: posix
gcc version 4.1.0 20050507 (experimental)
Comment 1 Francois-Xavier Coudert 2005-05-10 15:51:18 UTC
Yes, there is a bug with reshape and complex numbers (PR21127). It should be
fixed soon (a patch has been proposed).

*** This bug has been marked as a duplicate of 21127 ***
Comment 2 Tobias Schlüter 2005-06-08 17:32:10 UTC
Reopened, the bug is still present, and apparently completely unrelated to PR21127.
Comment 3 Andrew Pinski 2005-06-08 18:06:36 UTC
Confirmed.
Comment 4 Thomas Koenig 2005-06-08 18:59:09 UTC
Slightly reduced testcase:

$ cat 21480.f90
program reshape_bug
 implicit none
 complex :: a(2), b(2)

 a = (/(1.0, -1.0), (2.0, -2.0)/)
 write(*,*) 'from'
 write(*,*) a
 b=reshape(a, shape(a))
 write(*,*) 'to'
 write(*,*) b
end program reshape_bug

$ gfortran 21480.f90
$ ./a.out
 from
 (  1.000000    , -1.000000    ) (  2.000000    , -2.000000    )
 to
 (  1.000000    , -1.000000    ) ( 2.8025969E-45,  2.200292    )

In other words, this has nothing to do with arrays starting
at 0.
Comment 5 GCC Commits 2005-06-09 19:43:32 UTC
Subject: Bug 21480

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tkoenig@gcc.gnu.org	2005-06-09 19:43:27

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/m4 : reshape.m4 
	libgfortran/generated: reshape_c4.c reshape_c8.c reshape_i4.c 
	                       reshape_i8.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gfortran.dg: reshape-complex.f90 

Log message:
	2005-06-09  Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/21480
	* m4/reshape.m4:  Use sizeof (rtype_name) for sizes to be passed
	to reshape_packed.
	* generated/reshape_c4.c:  Regenerated.
	* generated/reshape_c8.c:  Regenerated.
	* generated/reshape_i4.c:  Regenerated.
	* generated/reshape_i8.c:  Regenerated.
	
	2005-06-09  Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/21480
	* gfortran.dg/reshape-complex.f90:  Add a test for a packed
	complex array.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.234&r2=1.235
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/reshape.m4.diff?cvsroot=gcc&r1=1.9&r2=1.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c4.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c8.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i4.c.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i8.c.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5618&r2=1.5619
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-complex.f90.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 6 Thomas Koenig 2005-06-09 19:46:19 UTC
Fixed in 4.1, waiting for 4.0 to reopen.
Comment 7 GCC Commits 2005-07-17 19:12:16 UTC
Subject: Bug 21480

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tkoenig@gcc.gnu.org	2005-07-17 19:12:07

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/generated: reshape_c4.c reshape_c8.c reshape_i4.c 
	                       reshape_i8.c 
	libgfortran/m4 : reshape.m4 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gfortran.dg: reshape-complex.f90 

Log message:
	2005-07-17  Thomas Koenig  <Thomas.Koenig@online.de>
	
	Backport from mainline.
	PR libfortran/21480
	* m4/reshape.m4:  Use sizeof (rtype_name) for sizes to be passed
	to reshape_packed.
	* generated/reshape_c4.c:  Regenerated.
	* generated/reshape_c8.c:  Regenerated.
	* generated/reshape_i4.c:  Regenerated.
	* generated/reshape_i8.c:  Regenerated.
	
	2005-07-17  Thomas Koenig  <Thomas.Koenig@online.de>
	
	Backport from mainline.
	PR libfortran/21480
	* gfortran.dg/reshape-complex.f90:  Add a test for a packed
	complex array.

Patches:
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.64&r2=1.163.2.65
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.3&r2=1.1.2.4
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.3&r2=1.1.2.4
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.12.2&r2=1.5.12.3
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.12.2&r2=1.5.12.3
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.3&r2=1.6.12.4
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.283&r2=1.5084.2.284
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-complex.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2

Comment 8 Thomas Koenig 2005-07-17 19:12:40 UTC
Fixed in 4.0.