===================================================================
@@ -164,6 +164,7 @@ realloc_string_callback (gfc_code **c, int *walk_s
gfc_expr *expr1, *expr2;
gfc_code *co = *c;
gfc_expr *n;
+ gfc_ref *ref;
if (co->op != EXEC_ASSIGN)
return 0;
@@ -170,7 +171,7 @@ realloc_string_callback (gfc_code **c, int *walk_s
expr1 = co->expr1;
if (expr1->ts.type != BT_CHARACTER || expr1->rank != 0
- || !expr1->symtree->n.sym->attr.allocatable)
+ || !expr1->ts.deferred)
return 0;
expr2 = gfc_discard_nops (co->expr2);
@@ -177,6 +178,13 @@ realloc_string_callback (gfc_code **c, int *walk_s
if (expr2->expr_type != EXPR_VARIABLE)
return 0;
+ /* Only substring expressions can be affected; substrings are always the
+ last reference. */
+
+ for (ref = expr2->ref; ref; ref = ref->next)
+ if (ref->type != REF_SUBSTRING)
+ return 0;
+
if (!gfc_check_dependency (expr1, expr2, true))
return 0;
@@ -190,7 +198,7 @@ realloc_string_callback (gfc_code **c, int *walk_s
current_code = c;
inserted_block = NULL;
changed_statement = NULL;
- n = create_var (expr2, "trim");
+ n = create_var (expr2, "realloc_string");
co->expr2 = n;
return 0;
}