OSDN Git Service

2006-09-09 Paul Thomas <pault@gcc.gnu.org>
authorjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Sep 2006 04:53:18 +0000 (04:53 +0000)
committerjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Sep 2006 04:53:18 +0000 (04:53 +0000)
PR fortran/28914
* trans-array.c (gfc_trans_array_constructor_value): Create a temporary
loop variable to hold the current loop variable in case it is modified
by the array constructor.

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

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

index a808926..6fbec93 100644 (file)
@@ -1,3 +1,10 @@
+2006-09-09  Paul Thomas <pault@gcc.gnu.org>
+
+       PR fortran/28914
+       * trans-array.c (gfc_trans_array_constructor_value): Create a temporary
+       loop variable to hold the current loop variable in case it is modified
+       by the array constructor.
+
 2006-09-07  Steven G. Kargl  <kargls@comcast.net>
 
        * gfortran.h (gfc_integer_info): Eliminate max_int.
index a976cb9..bf8e687 100644 (file)
@@ -1252,6 +1252,7 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock, tree type,
          tree exit_label;
          tree loopbody;
          tree tmp2;
+         tree tmp_loopvar;
 
          loopbody = gfc_finish_block (&body);
 
@@ -1260,6 +1261,11 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock, tree type,
          gfc_add_block_to_block (pblock, &se.pre);
          loopvar = se.expr;
 
+         /* Make a temporary, store the current value in that
+            and return it, once the loop is done.  */
+         tmp_loopvar = gfc_create_var (TREE_TYPE (loopvar), "loopvar");
+         gfc_add_modify_expr (pblock, tmp_loopvar, loopvar);
+
          /* Initialize the loop.  */
          gfc_init_se (&se, NULL);
          gfc_conv_expr_val (&se, c->iterator->start);
@@ -1327,6 +1333,9 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock, tree type,
          /* Add the exit label.  */
          tmp = build1_v (LABEL_EXPR, exit_label);
          gfc_add_expr_to_block (pblock, tmp);
+
+         /* Restore the original value of the loop counter.  */
+         gfc_add_modify_expr (pblock, loopvar, tmp_loopvar);
        }
     }
   mpz_clear (size);