http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49648
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-07-05 19:00:51 UTC --- Draft patch, which seems to fix some ref->u.ar->as issues for "p" - but not the one, I am looking for. At least the added assert now triggers. * * * Debugging shows that when resolving MAXMUL, one calls resolve_actual_arglist for SIZE's p. At that point "p's e->ref->u.ar.as == NULL, which is fixed. One then resolves MAXMUL in resolve_actual_arglist for getPhaseMatrix; if one now looks at getPhaseMatrix's e->symtree->n.sym->as->upper[0], one finds: (gdb) p arg->expr->symtree->n.sym->as->upper[0]->value.function.isym->id $11 = GFC_ISYM_SIZE (gdb) p arg->expr->symtree->n.sym->as->upper[0]->value.function.actual->expr->symtree->n.sym->name $12 = 0x2aaaaab42fa0 "p" (gdb) p arg->expr->symtree->n.sym->as->upper[0]->value.function.actual->expr->ref->u.ar.as. A syntax error in expression, near `'. (gdb) p arg->expr->symtree->n.sym->as->upper[0]->value.function.actual->expr->ref->u.ar.as $13 = (gfc_array_spec *) 0x159f830 Which also looks fine. Seemingly, the problem is really the result variable - which seems to be carried through: (gdb) p arg->expr->symtree->n.sym->result->name $17 = 0x2aaaaab42fb8 "pm" And as both "as" are different: (gdb) p arg->expr->symtree->n.sym->result->as $18 = (gfc_array_spec *) 0x159ef70 (gdb) p arg->expr->symtree->n.sym->as $19 = (gfc_array_spec *) 0x159cd40 it is not surprising that one get's at the end: (gdb) p arg->expr->symtree->n.sym->result->as->upper[0]->value.function.actual->expr->ref->u.ar.as $14 = (gfc_array_spec *) 0x0 If one removes the RESULT(), it works - even without the patch. --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -7506,6 +7521,7 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr) ar = &ref->u.ar; + gcc_assert (ar->as); if (ar->as->rank == 0 && ref->next != NULL) { /* Scalar coarray. */ --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -82,6 +82,11 @@ static bitmap_obstack labels_obstack; /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */ static bool inquiry_argument = false; + +/* Prototypes of static functions. */ +static gfc_try resolve_ref (gfc_expr *); + + int gfc_is_formal_arg (void) { @@ -1577,6 +1582,9 @@ resolve_actual_arglist (gfc_actual_arglist *arg, procedure_type ptype, && count_specific_procs (e) != 1) return FAILURE; + if (e->ref && e->symtree->n.sym->attr.use_assoc) + resolve_ref (e); + if (e->ts.type != BT_PROCEDURE) { save_need_full_assumed_size = need_full_assumed_size;