Handle NULL pointer dereference on SELECT RANK with an invalid
assumed-rank array declaration.
gcc/fortran/
PR fortran/96086
* match.c (gfc_match_select_rank): Catch NULL pointer
dereference.
* resolve.c (resolve_assoc_var): Catch NULL pointer dereference
that may occur after an illegal declaration.
if (expr2->symtree)
{
sym2 = expr2->symtree->n.sym;
- as = sym2->ts.type == BT_CLASS ? CLASS_DATA (sym2)->as : sym2->as;
+ as = (sym2->ts.type == BT_CLASS
+ && CLASS_DATA (sym2)) ? CLASS_DATA (sym2)->as : sym2->as;
}
if (expr2->expr_type != EXPR_VARIABLE
goto cleanup;
}
- if (expr2->ts.type == BT_CLASS)
+ if (expr2->ts.type == BT_CLASS && CLASS_DATA (sym2))
{
copy_ts_from_selector_to_associate (expr1, expr2);
if (as->corank != 0)
sym->attr.codimension = 1;
}
- else if (sym->ts.type == BT_CLASS && (!CLASS_DATA (sym)->as || sym->assoc->rankguessed))
+ else if (sym->ts.type == BT_CLASS
+ && CLASS_DATA (sym)
+ && (!CLASS_DATA (sym)->as || sym->assoc->rankguessed))
{
if (!CLASS_DATA (sym)->as)
CLASS_DATA (sym)->as = gfc_get_array_spec ();
--- /dev/null
+! { dg-do compile }
+! PR fortran/96086 - ICE in gfc_match_select_rank, at fortran/match.c:6645
+
+subroutine s
+ class(*) :: x(..) ! { dg-error "Assumed-rank array" }
+ select rank (y => x) ! { dg-error "CLASS variable" }
+ end select
+end