From: Paul Thomas Date: Thu, 11 Feb 2021 10:38:23 +0000 (+0000) Subject: Fortran: Fix ICE after error regression [PR99060]. X-Git-Tag: releases/gcc-10.3.0~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bc79d7b5d22c07a337b6399e08c1252d55ea5e0;p=thirdparty%2Fgcc.git Fortran: Fix ICE after error regression [PR99060]. 2021-02-11 Paul Thomas gcc/fortran PR fortran/99060 * primary.c (gfc_match_varspec): Test for non-null 'previous' before using its name in the error message. gcc/testsuite/ PR fortran/99060 * gfortran.dg/pr99060.f90: New test. (cherry picked from commit 5ee5415af8691640b0f7a5332b78d04ba309f4f0) --- diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index fa19f1b5bc9b..1fee18883dd3 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2352,11 +2352,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, component = NULL; if (intrinsic && !inquiry) - { - gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " - "type component %qs", name, previous->name); + { + if (previous) + gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " + "type component %qs", name, previous->name); + else + gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " + "type component", name); return MATCH_ERROR; - } + } else if (component == NULL && !inquiry) return MATCH_ERROR; diff --git a/gcc/testsuite/gfortran.dg/pr99060.f90 b/gcc/testsuite/gfortran.dg/pr99060.f90 new file mode 100644 index 000000000000..fdf3b1a724ed --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr99060.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! Test the fix for PR99060 in which the expression caused an ICE after the error. +! +! Contributed by Gerhard Steinmetz +! +program p + real :: a + print *, a%kind%n ! { dg-error "not an inquiry reference" } +end