This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: fortran/27662: Transpose doesn't work on function return
- From: "H. J. Lu" <hjl at lucon dot org>
- To: gcc-patches at gcc dot gnu dot org
- Cc: fortran at gcc dot gnu dot org
- Date: Thu, 18 May 2006 22:35:11 -0700
- Subject: PATCH: fortran/27662: Transpose doesn't work on function return
We zere the first stride to indicate a temporary. But if the first
stride of the temporary is used later, we will get the wrong result
as in PR fortran/27662. Does anyone know why we do this? Do we have
a testcase to show it is needed?
This patch fixes PR fortran/27662. But I have no ideas if it is the
correct fix.
H.J.
---
gcc/fortran/
2006-05-18 H.J. Lu <hongjiu.lu@intel.com>
PR fortran/27662
* trans-array.c (gfc_conv_expr_descriptor): Don't zere the
first stride to indicate a temporary.
* trans-expr.c (gfc_conv_function_call): Likewise.
gcc/testsuite/
2006-05-18 H.J. Lu <hongjiu.lu@intel.com>
PR fortran/27662
* gfortran.dg/temporary_1.f90: New file.
--- gcc/fortran/trans-array.c.transpose 2006-05-11 10:28:13.000000000 -0700
+++ gcc/fortran/trans-array.c 2006-05-18 20:11:01.000000000 -0700
@@ -4108,10 +4108,13 @@ gfc_conv_expr_descriptor (gfc_se * se, g
/* Finish the copying loops. */
gfc_trans_scalarizing_loops (&loop, &block);
- /* Set the first stride component to zero to indicate a temporary. */
desc = loop.temp_ss->data.info.descriptor;
+
+#if 0
+ /* Set the first stride component to zero to indicate a temporary. */
tmp = gfc_conv_descriptor_stride (desc, gfc_rank_cst[0]);
gfc_add_modify_expr (&loop.pre, tmp, gfc_index_zero_node);
+#endif
gcc_assert (is_gimple_lvalue (desc));
}
--- gcc/fortran/trans-expr.c.transpose 2006-04-16 11:18:33.000000000 -0700
+++ gcc/fortran/trans-expr.c 2006-05-18 20:10:14.000000000 -0700
@@ -2038,10 +2038,12 @@ gfc_conv_function_call (gfc_se * se, gfc
gfc_trans_create_temp_array (&se->pre, &se->post, se->loop, info, tmp,
false, !sym->attr.pointer, callee_alloc);
+#if 0
/* Zero the first stride to indicate a temporary. */
tmp = gfc_conv_descriptor_stride (info->descriptor, gfc_rank_cst[0]);
gfc_add_modify_expr (&se->pre, tmp,
convert (TREE_TYPE (tmp), integer_zero_node));
+#endif
/* Pass the temporary as the first argument. */
tmp = info->descriptor;
--- gcc/testsuite/gfortran.dg/temporary_1.f90.transpose 2006-05-18 22:26:54.000000000 -0700
+++ gcc/testsuite/gfortran.dg/temporary_1.f90 2006-05-18 22:25:54.000000000 -0700
@@ -0,0 +1,28 @@
+! { dg-do run }
+! PR 27662. Don't zero the first stride to indicate a temporary. It
+! may be used later.
+program pr27662
+ implicit none
+ real(kind=kind(1.0d0)), dimension (2, 2):: x, y, z;
+ integer i, j
+ x(1,1) = 1.d0
+ x(2,1) = 0.d0
+ x(1,2) = 0.d0
+ x(2,2) = 1.d0
+ z = matmul (x, transpose (test ()))
+ do i = 1, size (x, 1)
+ do j = 1, size (x, 2)
+ if (x (i, j) .ne. z (i, j)) call abort ()
+ end do
+ end do
+ close (10)
+
+contains
+ function test () result (res)
+ real(kind=kind(1.0d0)), dimension(2,2) :: res
+ res(1,1) = 1.d0
+ res(2,1) = 0.d0
+ res(1,2) = 0.d0
+ res(2,2) = 1.d0
+ end function
+end