diff mbox series

[fortran] Fix PR 90561

Message ID 8cc87fd5-ca82-ef10-6120-7d3e5a23ae8c@tkoenig.net
State New
Headers show
Series [fortran] Fix PR 90561 | expand

Commit Message

Thomas König Aug. 13, 2019, 12:59 p.m. UTC
Hello world,

this patch fixes a 9/10 regression by placing the variable used to
hold a string length at function scope.

I chose to implement this version of gfc_evaluate_now as a separate
function because I have a sneaking suspicion this may not be the
last time we are going to encounter something like that - better
have the function there for future use.

Regression-tested. OK for trunk and gcc-9?

Regards

	Thomas

Comments

Paul Richard Thomas Aug. 13, 2019, 1:38 p.m. UTC | #1
Hi Thomas,

Yes that's good to apply to 9 and 10 branches. I am certain that there
are other places where the new function will be very helpful.

Thanks for the patch.

Paul

On Tue, 13 Aug 2019 at 13:59, Thomas König <tk@tkoenig.net> wrote:
>
> Hello world,
>
> this patch fixes a 9/10 regression by placing the variable used to
> hold a string length at function scope.
>
> I chose to implement this version of gfc_evaluate_now as a separate
> function because I have a sneaking suspicion this may not be the
> last time we are going to encounter something like that - better
> have the function there for future use.
>
> Regression-tested. OK for trunk and gcc-9?
>
> Regards
>
>         Thomas
diff mbox series

Patch

Index: trans.h
===================================================================
--- trans.h	(Revision 274370)
+++ trans.h	(Arbeitskopie)
@@ -507,6 +507,7 @@  void gfc_conv_label_variable (gfc_se * se, gfc_exp
 /* 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);
Index: trans.c
===================================================================
--- trans.c	(Revision 274370)
+++ trans.c	(Arbeitskopie)
@@ -118,7 +118,20 @@  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:
    LHS <- RHS.  */
Index: trans-expr.c
===================================================================
--- trans-expr.c	(Revision 274370)
+++ trans-expr.c	(Arbeitskopie)
@@ -10796,7 +10796,8 @@  gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr
       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