re PR fortran/87336 (wrong output for pointer dummy assiocated to target actual argument)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 18 Sep 2018 17:58:20 +0000 (17:58 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 18 Sep 2018 17:58:20 +0000 (17:58 +0000)
2018-09-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/87336
* trans-array.c (gfc_get_array_span): Try to get the element
length of incomplete types. Return NULL_TREE otherwise.
(gfc_conv_expr_descriptor): Only set the 'span' field if the
above does not return NULL_TREE. Set 'span' field if possible
for all new descriptors.

2018-09-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/87336
* gfortran.dg/pointer_array_10.f90 : New test.
* gfortran.dg/assign_10.f90 : Increase 'parm' count to 20.
* gfortran.dg/transpose_optimization_2.f90 : Increase 'parm'
count to 72.

From-SVN: r264405

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

index 3980146aef7133159dcb88fedd8c40e0174a7700..5f10add3f0be5066357a3d2570415c03d5d345be 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/87336
+       * trans-array.c (gfc_get_array_span): Try to get the element
+       length of incomplete types. Return NULL_TREE otherwise.
+       (gfc_conv_expr_descriptor): Only set the 'span' field if the
+       above does not return NULL_TREE. Set 'span' field if possible
+       for all new descriptors.
+
 2018-09-17  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/64120
index 9565b7d8dd9ee70943c323feb491357381c5630c..95ea61550cf5adff4fccd1684cb07b60c0856b32 100644 (file)
@@ -849,10 +849,22 @@ gfc_get_array_span (tree desc, gfc_expr *expr)
   else
     {
       /* If none of the fancy stuff works, the span is the element
-        size of the array.  */
+        size of the array. Attempt to deal with unbounded character
+        types if possible. Otherwise, return NULL_TREE.  */
       tmp = gfc_get_element_type (TREE_TYPE (desc));
-      tmp = fold_convert (gfc_array_index_type,
-                         size_in_bytes (tmp));
+      if (tmp && TREE_CODE (tmp) == ARRAY_TYPE
+         && TYPE_MAX_VALUE (TYPE_DOMAIN (tmp)) == NULL_TREE)
+       {
+         if (expr->expr_type == EXPR_VARIABLE
+             && expr->ts.type == BT_CHARACTER)
+           tmp = fold_convert (gfc_array_index_type,
+                               gfc_get_expr_charlen (expr));
+         else
+           tmp = NULL_TREE;
+       }
+      else
+       tmp = fold_convert (gfc_array_index_type,
+                           size_in_bytes (tmp));
     }
   return tmp;
 }
@@ -7074,7 +7086,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
 
              /* ....and set the span field.  */
              tmp = gfc_get_array_span (desc, expr);
-             gfc_conv_descriptor_span_set (&se->pre, se->expr, tmp);
+             if (tmp != NULL_TREE)
+               gfc_conv_descriptor_span_set (&se->pre, se->expr, tmp);
            }
          else if (se->want_pointer)
            {
@@ -7344,13 +7357,9 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
       desc = info->descriptor;
       if (se->direct_byref && !se->byref_noassign)
        {
-         /* For pointer assignments we fill in the destination....  */
+         /* For pointer assignments we fill in the destination.  */
          parm = se->expr;
          parmtype = TREE_TYPE (parm);
-
-         /* ....and set the span field.  */
-         tmp = gfc_get_array_span (desc, expr);
-         gfc_conv_descriptor_span_set (&loop.pre, parm, tmp);
        }
       else
        {
@@ -7388,6 +7397,11 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
            }
        }
 
+      /* Set the span field.  */
+      tmp = gfc_get_array_span (desc, expr);
+      if (tmp != NULL_TREE)
+       gfc_conv_descriptor_span_set (&loop.pre, parm, tmp);
+
       offset = gfc_index_zero_node;
 
       /* The following can be somewhat confusing.  We have two
index 7a7a7c24563008095b15f8e6f152fd960922747e..29481f07fc7cfc81d60522aa27b87d62e3581ae2 100644 (file)
@@ -1,3 +1,11 @@
+2018-09-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/87336
+       * gfortran.dg/pointer_array_10.f90 : New test.
+       * gfortran.dg/assign_10.f90 : Increase 'parm' count to 20.
+       * gfortran.dg/transpose_optimization_2.f90 : Increase 'parm'
+       count to 72.
+
 2018-09-18  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/85065
index 42f66e5b5337dcf6ec83a88a03942a3d47a84aad..6e57bef1650e5a564c2b3b82d472810dc05f76ec 100644 (file)
@@ -23,5 +23,5 @@ end
 ! cases will all yield a temporary, so that atmp appears 18 times.
 ! Note that it is the kind conversion that generates the temp.
 !
-! { dg-final { scan-tree-dump-times "parm" 18 "original" } }
+! { dg-final { scan-tree-dump-times "parm" 20 "original" } }
 ! { dg-final { scan-tree-dump-times "atmp" 18 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/pointer_array_10.f90 b/gcc/testsuite/gfortran.dg/pointer_array_10.f90
new file mode 100644 (file)
index 0000000..4e7b140
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do run }
+!
+! Test the fix for PR87336, in which the 'span' field of the array
+! descriptor, passed to 'show', was not set.
+!
+! Contributed by Juergen Reuter  <juergen.reuter@desy.de> following
+! a posting to clf by 'Spectrum'.
+!
+program main
+  implicit none
+  integer, target :: a( 2:4 )
+
+  a = [2,3,4]
+!  print *, "a [before] = ", a
+  call show( a )
+!  print *, "a [after]  = ", a
+  if (any (a .ne. [200,300,400])) stop 1
+
+contains
+  subroutine show( arr )
+    integer, pointer, intent(in) :: arr(:)
+!    print *, "arr = ", arr
+!    print *, "bounds = ", lbound(arr), ubound(arr)
+    arr(:) = [200,300,400]
+!    print *, "arr2= ", arr
+  end subroutine show
+  end program
index 84b5a9e560eccaeea5bf25cdd04b034c8be78b6c..4748da1954702a72f7f6f8b2c4349fbeefc9c304 100644 (file)
@@ -60,5 +60,5 @@ end
 !
 ! The check below for temporaries gave 14 and 33 for "parm" and "atmp".
 !
-! { dg-final { scan-tree-dump-times "parm" 66 "original" } }
+! { dg-final { scan-tree-dump-times "parm" 72 "original" } }
 ! { dg-final { scan-tree-dump-times "atmp" 12 "original" } }