re PR fortran/87782 (runtime error: load of value 1818451807, which is not a valid...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 1 Nov 2018 19:50:14 +0000 (19:50 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 1 Nov 2018 19:50:14 +0000 (19:50 +0000)
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.

From-SVN: r265730

gcc/fortran/ChangeLog
gcc/fortran/frontend-passes.c

index 31e3fdd12eca71f36450d208e1f62bd77355c381..134c43db644a2566b91dcb5357ecd3f33f75fc4f 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2018-11-01  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/40196
index 2c095cb8d5e51df6a692e3ac4e9c4580b5ea79e5..19930305bd16590091c4a90779b301264f56704b 100644 (file)
@@ -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)