trans-intrinsic.c (walk_coarray): New function.
authorMikael Morin <mikael.morin@sfr.fr>
Fri, 7 Oct 2011 19:52:34 +0000 (21:52 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Fri, 7 Oct 2011 19:52:34 +0000 (19:52 +0000)
* trans-intrinsic.c (walk_coarray): New function.
(convert_element_to_coarray_ref): Move code to walk_coarray. Remove.
(trans-this_image, trans_image_index, conv_intrinsic_cobound):
Use walk_coarray.

From-SVN: r179684

gcc/fortran/ChangeLog
gcc/fortran/trans-intrinsic.c

index 8bcaf58224cbf9e3082885961d0fb1f3beacb3c3..e7a9941b9cfa9f8df931ed3f130d5653a2ee9ca2 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-07  Mikael Morin  <mikael.morin@sfr.fr>
+
+       * trans-intrinsic.c (walk_coarray): New function.
+       (convert_element_to_coarray_ref): Move code to walk_coarray. Remove.
+       (trans-this_image, trans_image_index, conv_intrinsic_cobound):
+       Use walk_coarray.
+
 2011-10-07  Mikael Morin  <mikael.morin@sfr.fr>
 
        * trans-array.c (gfc_conv_expr_descriptor): Add out-of-the-scalarizer
index c216873b3ff4d7f6be8e2f97ebc33d9c227c83f7..bc21b020db54a0acdc00bc2bb0b3960bb76fe365 100644 (file)
@@ -924,18 +924,32 @@ gfc_conv_intrinsic_exponent (gfc_se *se, gfc_expr *expr)
 /* Convert the last ref of a scalar coarray from an AR_ELEMENT to an
    AR_FULL, suitable for the scalarizer.  */
 
-static void
-convert_element_to_coarray_ref (gfc_expr *expr)
+static gfc_ss *
+walk_coarray (gfc_expr *e)
 {
-  gfc_ref *ref;
+  gfc_ss *ss;
 
-  for (ref = expr->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->next == NULL
-       && ref->u.ar.codimen)
-      {
-       ref->u.ar.type = AR_FULL;
-       break;
-      }
+  gcc_assert (gfc_get_corank (e) > 0);
+
+  ss = gfc_walk_expr (e);
+
+  /* Fix scalar coarray.  */
+  if (ss == gfc_ss_terminator)
+    {
+      gfc_ref *ref;
+
+      ss = gfc_get_array_ss (gfc_ss_terminator, e, 0, GFC_SS_SECTION);
+
+      ref = e->ref;
+      while (ref->next)
+       ref = ref->next;
+
+      gcc_assert (ref->type == REF_ARRAY && ref->u.ar.codimen > 0);
+      ref->u.ar.type = AR_FULL;
+      ss->data.info.ref = ref;
+    }
+
+  return ss;
 }
 
 
@@ -969,9 +983,7 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
 
   /* Obtain the descriptor of the COARRAY.  */
   gfc_init_se (&argse, NULL);
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (expr->value.function.actual->expr);
+  ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   argse.want_coarray = 1;
@@ -1157,9 +1169,7 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
 
   /* Obtain the descriptor of the COARRAY.  */
   gfc_init_se (&argse, NULL);
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (expr->value.function.actual->expr);
+  ss = walk_coarray (expr->value.function.actual->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   argse.want_coarray = 1;
@@ -1484,9 +1494,7 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
   gcc_assert (arg->expr->expr_type == EXPR_VARIABLE);
   corank = gfc_get_corank (arg->expr);
 
-  if (expr->value.function.actual->expr->rank == 0)
-    convert_element_to_coarray_ref (expr->value.function.actual->expr);
-  ss = gfc_walk_expr (arg->expr);
+  ss = walk_coarray (arg->expr);
   gcc_assert (ss != gfc_ss_terminator);
   ss->data.info.codimen = corank;
   gfc_init_se (&argse, NULL);