gfc_expr *expr1, *expr2;
gfc_code *co = *c;
gfc_expr *n;
+ gfc_ref *ref;
+ bool found_substr;
if (co->op != EXEC_ASSIGN)
return 0;
expr1 = co->expr1;
if (expr1->ts.type != BT_CHARACTER || expr1->rank != 0
- || !expr1->symtree->n.sym->attr.allocatable)
+ || !gfc_expr_attr(expr1).allocatable
+ || !expr1->ts.deferred)
return 0;
expr2 = gfc_discard_nops (co->expr2);
if (expr2->expr_type != EXPR_VARIABLE)
return 0;
+ found_substr = false;
+ for (ref = expr2->ref; ref; ref = ref->next)
+ {
+ if (ref->type == REF_SUBSTRING)
+ {
+ found_substr = true;
+ break;
+ }
+ }
+ if (!found_substr)
+ return 0;
+
if (!gfc_check_dependency (expr1, expr2, true))
return 0;
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;
}
--- /dev/null
+! { dg-do compile }
+! Make sure there is only one instance of a temporary variable here.
+! { dg-options "-fdump-tree-original" }
+
+SUBROUTINE prtdata(ilen)
+ INTEGER :: ilen
+ character(len=ilen), allocatable :: cline(:)
+ allocate(cline(2))
+ cline(1) = 'a'
+ cline(1)(2:3) = cline(1)(1:2)
+ cline(2) = cline(1)
+ print *,c
+END SUBROUTINE prtdata
+! { dg-final { scan-tree-dump-not "__var_" "original" } }
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! PR fortran/71902 - make sure that component references are followed
+! for dependency analysis.
+program main
+ type foo
+ character(len=:), allocatable :: x
+ end type foo
+ type(foo) :: a
+ a%x = 'asdf'
+ a%x = a%x(2:3)
+ print *,a%x
+end program main
+! { dg-final { scan-tree-dump-times "__var_1" 4 "original" } }