This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] PR 15957 Fix builtin reshape


Per the standard, shape(reshape(source, shape, order, pad)) == shape. We
violated this assumption in the implementation in gfc_simplify_reshape. Below
one-line patch fixes this. Testcase attached.

Built and tested. Ok?

- Tobi

2004-09-20  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/15957
	* simplify.c (gfc_simplify_reshape): Set shape of return value
	correctly.

Index: simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/simplify.c,v
retrieving revision 1.10
diff -u -p -r1.10 simplify.c
--- simplify.c  8 Sep 2004 14:33:02 -0000       1.10
+++ simplify.c  20 Sep 2004 16:51:20 -0000
@@ -2822,7 +2822,7 @@ inc:
   e->shape = gfc_get_shape (rank);

   for (i = 0; i < rank; i++)
-    mpz_init_set_ui (e->shape[i], shape[order[i]]);
+    mpz_init_set_ui (e->shape[i], shape[i]);

   e->ts = head->expr->ts;
   e->rank = rank;

! PR 15957
! we used to return the wrong shape when the order parameter was used
! in reshape.
!
INTEGER, parameter :: i(2,3) = reshape ((/1,2,3,4,5,6/), (/2,3/)), &
     j(2,4) = reshape ((/1,2,3,4,5,6/), (/2,4/), (/0,0/), (/2,1/))

integer :: k(2,3), m(2,4), n(2,3), o(2,4)

k(1,:) = (/ 1, 3, 5 /)
k(2,:) = (/ 2, 4, 6 /)

m(1,:) = (/ 1, 2, 3, 4 /)
m(2,:) = (/ 5, 6, 0, 0 /)

! check that reshape does the right thing while constant folding
if (any(i /= k)) call abort()
if (any(j /= m)) call abort()

! check that reshape does the right thing at runtime
n = reshape ((/1,2,3,4,5,6/), (/2,3/))
if (any(n /= k)) call abort()
o = reshape ((/1,2,3,4,5,6/), (/2,4/), (/0,0/), (/2,1/))
if (any(o /= m)) call abort()
end 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]