https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93956
--- Comment #16 from Paul Thomas <pault at gcc dot gnu.org> --- Hi Thomas, I am sorry that you are having such a hassle with this - perhaps this helps? > > I assume that the span is not used correctly in the > function. Yes, that is correct. Within 'foo', we have a.0 = (integer(kind=4)[0:D.3967] * restrict) a->data; and the sum is inlined as: while (1) { if (S.10 > D.3961) goto L.1; val.9 = (*a.0)[S.10 * D.3963 + D.3960] + val.9; S.10 = S.10 + 1; } L.1:; so that the sum becomes: sum(r(1:500)%u) + sum(r(1:500)%v). This fixes the problem at the expense of more temporaries but regtests fine: diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index a9fa03ad153..8ca2b9bb3cb 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1098,10 +1098,14 @@ is_subref_array (gfc_expr * e) bool seen_array; gfc_symbol *sym; - if (e->expr_type != EXPR_VARIABLE) - return false; - sym = e->symtree->n.sym; + if (e->expr_type == EXPR_VARIABLE) + sym = e->symtree->n.sym; + else if (e->expr_type == EXPR_FUNCTION + && gfc_expr_attr (e).subref_array_pointer) + return true; + else + return false; if (sym->attr.subref_array_pointer) return true; @@ -4242,7 +4246,7 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue, if (rvalue->expr_type == EXPR_NULL) return true; - if (rvalue->expr_type == EXPR_VARIABLE && is_subref_array (rvalue)) + if (is_subref_array (rvalue)) lvalue->symtree->n.sym->attr.subref_array_pointer = 1; attr = gfc_expr_attr (rvalue); Paul