diff mbox series

[fortran] Fux PR 87782

Message ID 9ec89e87-8aa8-1643-a813-a8fb1dff3010@netcologne.de
State New
Headers show
Series [fortran] Fux PR 87782 | expand

Commit Message

Thomas Koenig Nov. 1, 2018, 7:13 p.m. UTC
Hello world,

the attached patch fixes the PR by not trying to determine the length
of the base symbol when there is a substring with a length which
is not constant.  This might make the length of temporary strings
generated by the front end optimization pass shorter, while inserting
an additional call to determine length of the substring.

No test case because the failure was only exposed by an instrumented
compiler.

Regression-tested. OK for trunk?

Regards

	Thomas

2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/87782
         * frontend-passes.c (constant_string_length): If there is a
         substring with a length which cannot be reduced to a constant,
         return NULL.

Comments

Janne Blomqvist Nov. 1, 2018, 7:20 p.m. UTC | #1
On Thu, Nov 1, 2018 at 9:13 PM Thomas Koenig <tkoenig@netcologne.de> wrote:

> Hello world,
>
> the attached patch fixes the PR by not trying to determine the length
> of the base symbol when there is a substring with a length which
> is not constant.  This might make the length of temporary strings
> generated by the front end optimization pass shorter, while inserting
> an additional call to determine length of the substring.
>
> No test case because the failure was only exposed by an instrumented
> compiler.
>
> Regression-tested. OK for trunk?
>

Ok, thanks!
diff mbox series

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 265722)
+++ frontend-passes.c	(Arbeitskopie)
@@ -638,23 +638,27 @@  constant_string_length (gfc_expr *e)
 	return gfc_copy_expr(length);
     }
 
-  /* Return length of substring, if constant. */
+  /* See if there is a substring. If it has a constant length, return
+     that and NULL otherwise.  */
   for (ref = e->ref; ref; ref = ref->next)
     {
-      if (ref->type == REF_SUBSTRING
-	  && gfc_dep_difference (ref->u.ss.end, ref->u.ss.start, &value))
+      if (ref->type == REF_SUBSTRING)
 	{
-	  res = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind,
-				       &e->where);
+	  if (gfc_dep_difference (ref->u.ss.end, ref->u.ss.start, &value))
+	    {
+	      res = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind,
+					   &e->where);
 
-	  mpz_add_ui (res->value.integer, value, 1);
-	  mpz_clear (value);
-	  return res;
+	      mpz_add_ui (res->value.integer, value, 1);
+	      mpz_clear (value);
+	      return res;
+	    }
+	  else
+	    return NULL;
 	}
     }
 
   /* Return length of char symbol, if constant.  */
-
   if (e->symtree && e->symtree->n.sym->ts.u.cl
       && e->symtree->n.sym->ts.u.cl->length
       && e->symtree->n.sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)