https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99139
--- Comment #5 from kargl at gcc dot gnu.org --- (In reply to sandra from comment #4) > The problem noted in comment 1 looks related to PR 102641 -- > automatically-inserted implicit initialization code can't cope with > assumed-rank arrays. I don't think it is related. PR102601 involves default initialization and/or deallocation of an actual argument associated with an intent(out) assumed-rank dummy argument. > I tested the patch in comment 2 and saw a whole lot of regressions (ICEs). > :-( The patch in comment #2 needed to be moved down into the 'if (m == MATCH_YES)' block where 'expr2 != NULL'. The following has been regtested with no new regressions. diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 5eb6d0e1c1d..0a030ae01df 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -6770,8 +6770,20 @@ gfc_match_select_rank (void) gfc_current_ns = gfc_build_block_ns (ns); m = gfc_match (" %n => %e", name, &expr2); + if (m == MATCH_YES) { + /* If expr2 corresponds to an implicitly typed variable, then the + actual type of the variable may not have been set. Set it here. */ + if (!gfc_current_ns->seen_implicit_none + && expr2->expr_type == EXPR_VARIABLE + && expr2->ts.type == BT_UNKNOWN + && expr2->symtree && expr2->symtree->n.sym) + { + gfc_set_default_type (expr2->symtree->n.sym, 0, gfc_current_ns); + expr2->ts.type = expr2->symtree->n.sym->ts.type; + } + expr1 = gfc_get_expr (); expr1->expr_type = EXPR_VARIABLE; expr1->where = expr2->where;