2007-08-13 Paul Thomas <pault@gcc.gnu.org>
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 Aug 2007 06:16:03 +0000 (06:16 +0000)
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 Aug 2007 06:16:03 +0000 (06:16 +0000)
PR fortran/32962
* trans-array.c (gfc_conv_array_transpose): Set the offset
of the destination to zero if the loop is zero based.

2007-08-13  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/32962
* gfortran.dg/transpose_1.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127391 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/transpose_1.f90 [new file with mode: 0644]

index 7ea4735..faa76ef 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-13  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/32962
+       * trans-array.c (gfc_conv_array_transpose): Set the offset
+       of the destination to zero if the loop is zero based.
+
 2007-08-12  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/29600
index 1cf00fd..31d177b 100644 (file)
@@ -783,13 +783,18 @@ gfc_conv_array_transpose (gfc_se * se, gfc_expr * expr)
   dest_info->data = gfc_conv_descriptor_data_get (src);
   gfc_conv_descriptor_data_set (&se->pre, dest, dest_info->data);
 
-  /* Copy the offset.  This is not changed by transposition: the top-left
-     element is still at the same offset as before.  */
-  dest_info->offset = gfc_conv_descriptor_offset (src);
+  /* Copy the offset.  This is not changed by transposition; the top-left
+     element is still at the same offset as before, except where the loop
+     starts at zero.  */
+  if (!integer_zerop (loop->from[0]))
+    dest_info->offset = gfc_conv_descriptor_offset (src);
+  else
+    dest_info->offset = gfc_index_zero_node;
+
   gfc_add_modify_expr (&se->pre,
                       gfc_conv_descriptor_offset (dest),
                       dest_info->offset);
-
+         
   if (dest_info->dimen > loop->temp_dim)
     loop->temp_dim = dest_info->dimen;
 }
index b039444..c5009c4 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-13  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/32962
+       * gfortran.dg/transpose_1.f90: New test.
+
 2007-08-12  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/29600
diff --git a/gcc/testsuite/gfortran.dg/transpose_1.f90 b/gcc/testsuite/gfortran.dg/transpose_1.f90
new file mode 100644 (file)
index 0000000..9ad784e
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do compile }
+! Tests the fix for PR32962, in which the result of TRANSPOSE, when
+! an actual argument of an elemental intrinsic would receive the
+! wrong offset.
+!
+! Contributed by Wirawan Purwanto <wirawan0@gmail.com>
+!
+  real(kind=8), allocatable :: b(:,:)
+  real(kind=8) :: a(2,2), c(2,2)
+  i = 2
+  allocate (b(i,i))
+  a(1,1) = 2
+  a(2,1) = 3
+  a(1,2) = 7
+  a(2,2) = 11
+  call foo
+  call bar
+  if (any (c .ne. b)) call abort
+contains
+  subroutine foo
+    b = cos(transpose(a))
+  end subroutine
+  subroutine bar
+    c = transpose(a)
+    c = cos(c)
+  end subroutine
+end program