re PR fortran/90561 (ICE in gimplify_var_or_parm_decl, at gimplify.c:2747)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 13 Aug 2019 15:08:10 +0000 (15:08 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 13 Aug 2019 15:08:10 +0000 (15:08 +0000)
2019-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/90561
* trans.h (gfc_evaluate_now_function_scope): New function.
* trans.c (gfc_evaluate_now_function_scope): New function.
* trans-expr.c (gfc_trans_assignment): Use it.

2019-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/90561
* gfortran.dg/deferred_character_34.f90: New test.

From-SVN: r274383

gcc/fortran/trans-expr.c
gcc/fortran/trans.c
gcc/fortran/trans.h
gcc/testsuite/gfortran.dg/deferred_character_34.f90 [new file with mode: 0644]

index a4e8351110ac247f77d213f2cc76ea00eb75206a..2adc112bcecda6f46079c0912f11264216c3f415 100644 (file)
@@ -10796,7 +10796,8 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
       if (expr1->ts.deferred
          && gfc_expr_attr (expr1).allocatable
          && gfc_check_dependency (expr1, expr2, true))
-       rse.string_length = gfc_evaluate_now (rse.string_length, &rse.pre);
+       rse.string_length =
+         gfc_evaluate_now_function_scope (rse.string_length, &rse.pre);
       string_length = rse.string_length;
     }
   else
index 303abd994c5812b1d8e02e8db83b105107d8597f..84511477b393f52309d9a3c78f31a8b7c891b5be 100644 (file)
@@ -118,6 +118,19 @@ gfc_evaluate_now (tree expr, stmtblock_t * pblock)
   return gfc_evaluate_now_loc (input_location, expr, pblock);
 }
 
+/* Like gfc_evaluate_now, but add the created variable to the
+   function scope.  */
+
+tree
+gfc_evaluate_now_function_scope (tree expr, stmtblock_t * pblock)
+{
+  tree var;
+  var = gfc_create_var_np (TREE_TYPE (expr), NULL);
+  gfc_add_decl_to_function (var);
+  gfc_add_modify (pblock, var, expr);
+
+  return var;
+}
 
 /* Build a MODIFY_EXPR node and add it to a given statement block PBLOCK.
    A MODIFY_EXPR is an assignment:
index 0305d331ff745f4ec7109c5a3aa30f3a6bf60461..a3726e8414036babf6729a956537922bf8d9266c 100644 (file)
@@ -507,6 +507,7 @@ void gfc_conv_label_variable (gfc_se * se, gfc_expr * expr);
 /* If the value is not constant, Create a temporary and copy the value.  */
 tree gfc_evaluate_now_loc (location_t, tree, stmtblock_t *);
 tree gfc_evaluate_now (tree, stmtblock_t *);
+tree gfc_evaluate_now_function_scope (tree, stmtblock_t *);
 
 /* Find the appropriate variant of a math intrinsic.  */
 tree gfc_builtin_decl_for_float_kind (enum built_in_function, int);
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_34.f90 b/gcc/testsuite/gfortran.dg/deferred_character_34.f90
new file mode 100644 (file)
index 0000000..2040841
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do run }
+! PR fortran/90561
+! This used to ICE.
+! Original test case by Gerhard Steinmetz.
+program p
+   character(:), allocatable :: z(:)
+   z = [character(2):: 'ab', 'xy']
+   z = z(2)
+   if (any(z /= 'xy')) stop 1
+end