------- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-05-04 22:15 
-------
Here's a patch that avoids multiple evaluation of substring start and end
indices. It was tested on the testcase, also by changing the (start:) range
into a (:end) range, and also by using -fbounds-check (which evaluated the
start and end indices a few other times). It's not fully regtested yet, though.



Index: trans-expr.c
===================================================================
--- trans-expr.c        (revision 124285)
+++ trans-expr.c        (working copy)
@@ -261,6 +261,9 @@ gfc_conv_substring (gfc_se * se, gfc_ref
     gfc_conv_string_parameter (se);
   else
     {
+      /* Avoid multiple evaluation of substring start.  */
+      start.expr = gfc_evaluate_now (start.expr, &se->pre);
+
       /* Change the start of the string.  */
       if (TYPE_STRING_FLAG (TREE_TYPE (se->expr)))
        tmp = se->expr;
@@ -279,6 +282,8 @@ gfc_conv_substring (gfc_se * se, gfc_ref
       gfc_conv_expr_type (&end, ref->u.ss.end, gfc_charlen_type_node);
       gfc_add_block_to_block (&se->pre, &end.pre);
     }
+  end.expr = gfc_evaluate_now (end.expr, &se->pre);
+
   if (flag_bounds_check)
     {
       tree nonempty = fold_build2 (LE_EXPR, boolean_type_node,


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
           Keywords|                            |patch
   Last reconfirmed|2007-04-27 18:59:17         |2007-05-04 22:15:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31725

Reply via email to