OSDN Git Service

2008-11-16 Paul Thomas <pault@gcc.gnu.org>
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 16 Nov 2008 12:11:53 +0000 (12:11 +0000)
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 16 Nov 2008 12:11:53 +0000 (12:11 +0000)
PR fortran/38119
* trans-array.c (gfc_trans_create_temp_array): Set the
loop->from to zero and the renormalisation of loop->to for all
dimensions.

2008-11-16  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/38119
* gfortran.dg/array_temporaries_3.f90: New test.

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

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

index ca9f865..4e3ac60 100644 (file)
@@ -1,5 +1,12 @@
 2008-11-16  Paul Thomas  <pault@gcc.gnu.org>
 
+       PR fortran/38119
+       * trans-array.c (gfc_trans_create_temp_array): Set the
+       loop->from to zero and the renormalisation of loop->to for all
+       dimensions.
+
+2008-11-16  Paul Thomas  <pault@gcc.gnu.org>
+
        PR fortran/37926
        * trans-expr.c (gfc_free_interface_mapping): Null sym->formal
        (gfc_add_interface_mapping): Copy the pointer to the formal
index 9cede5c..9c48c42 100644 (file)
@@ -644,18 +644,12 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post,
   for (dim = 0; dim < info->dimen; dim++)
     {
       n = loop->order[dim];
-      if (n < loop->temp_dim)
-      gcc_assert (integer_zerop (loop->from[n]));
-      else
-       {
-         /* Callee allocated arrays may not have a known bound yet.  */
-         if (loop->to[n])
-           loop->to[n] =
-               gfc_evaluate_now (fold_build2 (MINUS_EXPR,
-                                 gfc_array_index_type, loop->to[n],
-                                 loop->from[n]), pre);
-         loop->from[n] = gfc_index_zero_node;
-       }
+      /* Callee allocated arrays may not have a known bound yet.  */
+      if (loop->to[n])
+       loop->to[n] = gfc_evaluate_now (fold_build2 (MINUS_EXPR,
+                                       gfc_array_index_type,
+                                       loop->to[n], loop->from[n]), pre);
+      loop->from[n] = gfc_index_zero_node;
 
       info->delta[dim] = gfc_index_zero_node;
       info->start[dim] = gfc_index_zero_node;
index b831046..3fc9162 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-16  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/38119
+       * gfortran.dg/array_temporaries_3.f90: New test.
+
 2008-11-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/37294
diff --git a/gcc/testsuite/gfortran.dg/array_temporaries_3.f90 b/gcc/testsuite/gfortran.dg/array_temporaries_3.f90
new file mode 100644 (file)
index 0000000..929a4c0
--- /dev/null
@@ -0,0 +1,31 @@
+! { dg-do run }
+! PR38119 - The scalarizer got the loop size wrong
+! for the temporary coming from the call to 'same'.
+!
+! Contributed by Mikael Morin <mikael.morin@tele2.fr>
+! based on a program by Vivek Rao.
+!
+module bar
+  implicit none
+  character(len = 2) :: c(1)
+contains
+  elemental function trim_append (xx,yy) result(xy)
+    character (len = *), intent(in) :: xx,yy
+    character (len = len (xx) + len (yy)) :: xy
+    xy = trim (xx) // trim (yy)
+  end function trim_append
+  function same(xx) result(yy)
+    character (len = *), intent(in) :: xx(:)
+    character (len = len (xx))       :: yy(size (xx))
+    yy = xx
+  end function same
+  subroutine xmain()
+    c =  trim_append(["a"],same(["b"]))  ! The problem occurred here
+  end subroutine xmain
+end module bar
+  use bar
+  call xmain
+  if (c(1) .ne. "ab") call abort
+end
+! { dg-final { cleanup-modules "bar" } }
+