OSDN Git Service

* trans-array.c (constant_array_constructor_loop_size):
authormikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2011 23:51:04 +0000 (23:51 +0000)
committermikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2011 23:51:04 +0000 (23:51 +0000)
Handle multiple loops.

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

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

index 091ae6e..e359eca 100644 (file)
@@ -1,5 +1,10 @@
 2011-11-03  Mikael Morin  <mikael@gcc.gnu.org>
 
 2011-11-03  Mikael Morin  <mikael@gcc.gnu.org>
 
+       * trans-array.c (constant_array_constructor_loop_size):
+       Handle multiple loops.
+
+2011-11-03  Mikael Morin  <mikael@gcc.gnu.org>
+
        * trans-array.c (get_rank, get_loop_upper_bound_for_array):
        New functions.
        (gfc_trans_array_constructor): Handle multiple loops.
        * trans-array.c (get_rank, get_loop_upper_bound_for_array):
        New functions.
        (gfc_trans_array_constructor): Handle multiple loops.
index 083ce5c..299bd80 100644 (file)
@@ -2053,32 +2053,38 @@ get_rank (gfc_loopinfo *loop)
    iteration count of the loop if suitable, and NULL_TREE otherwise.  */
 
 static tree
    iteration count of the loop if suitable, and NULL_TREE otherwise.  */
 
 static tree
-constant_array_constructor_loop_size (gfc_loopinfo * loop)
+constant_array_constructor_loop_size (gfc_loopinfo * l)
 {
 {
+  gfc_loopinfo *loop;
   tree size = gfc_index_one_node;
   tree tmp;
   tree size = gfc_index_one_node;
   tree tmp;
-  int i;
+  int i, total_dim;
+
+  total_dim = get_rank (l);
 
 
-  for (i = 0; i < loop->dimen; i++)
+  for (loop = l; loop; loop = loop->parent)
     {
     {
-      /* If the bounds aren't constant, return NULL_TREE.  */
-      if (!INTEGER_CST_P (loop->from[i]) || !INTEGER_CST_P (loop->to[i]))
-       return NULL_TREE;
-      if (!integer_zerop (loop->from[i]))
+      for (i = 0; i < loop->dimen; i++)
        {
        {
-         /* Only allow nonzero "from" in one-dimensional arrays.  */
-         if (loop->dimen != 1)
+         /* If the bounds aren't constant, return NULL_TREE.  */
+         if (!INTEGER_CST_P (loop->from[i]) || !INTEGER_CST_P (loop->to[i]))
            return NULL_TREE;
            return NULL_TREE;
-         tmp = fold_build2_loc (input_location, MINUS_EXPR,
-                                gfc_array_index_type,
-                                loop->to[i], loop->from[i]);
+         if (!integer_zerop (loop->from[i]))
+           {
+             /* Only allow nonzero "from" in one-dimensional arrays.  */
+             if (total_dim != 1)
+               return NULL_TREE;
+             tmp = fold_build2_loc (input_location, MINUS_EXPR,
+                                    gfc_array_index_type,
+                                    loop->to[i], loop->from[i]);
+           }
+         else
+           tmp = loop->to[i];
+         tmp = fold_build2_loc (input_location, PLUS_EXPR,
+                                gfc_array_index_type, tmp, gfc_index_one_node);
+         size = fold_build2_loc (input_location, MULT_EXPR,
+                                 gfc_array_index_type, size, tmp);
        }
        }
-      else
-       tmp = loop->to[i];
-      tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-                            tmp, gfc_index_one_node);
-      size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-                             size, tmp);
     }
 
   return size;
     }
 
   return size;