From 3d137b75febd1a4ad70bcc64e0f79198f5571b86 Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Mon, 1 Jun 2020 08:15:31 +0100 Subject: Fortran : ICE on invalid code PR95398 The CLASS_DATA macro is used to shorten the code accessing the derived components of an expressions type specification. If the type is not BT_CLASS the derived pointer is NULL resulting in an ICE. To avoid dereferencing a NULL pointer the type should be BT_CLASS. 2020-09-01 Steven G. Kargl gcc/fortran PR fortran/95398 * resolve.c (resolve_select_type): Add check for BT_CLASS type before using the CLASS_DATA macro which will have a NULL pointer to derive components if it isn't BT_CLASS. 2020-09-01 Mark Eggleston gcc/testsuite PR fortran/95398 * gfortran.dg/pr95398.f90: New test. --- gcc/fortran/resolve.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/fortran/resolve.c') diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 6caddcf..e423271 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -9259,7 +9259,9 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) ? CLASS_DATA (code->expr2)->ts.u.derived : code->expr2->ts.u.derived; } - if (code->expr2->rank && CLASS_DATA (code->expr1)->as) + if (code->expr2->rank + && code->expr1->ts.type == BT_CLASS + && CLASS_DATA (code->expr1)->as) CLASS_DATA (code->expr1)->as->rank = code->expr2->rank; /* F2008: C803 The selector expression must not be coindexed. */ -- cgit v1.1