From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 930CC383AB6E; Tue, 13 Dec 2022 18:09:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 930CC383AB6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670954950; bh=egI27fsHd6c4VXo5tLpguGi8xA1pFe4UoJytLKrCV+s=; h=From:To:Subject:Date:From; b=iMlSoWhc3wM1ozCBVFyStTYJwVl/8uTZxu/TDFP5aTBKx8wgX0MWz53GBJpVakWwQ B0hvA8M30TmQSNG7Onwk7l0icsE+Rlrm5KOZyFAcouUUXM56X3E9q5rA1plk0/x8G9 /QNaVT/jIC3tDjRc8Pm+OfVIt1ptm82cENsluv4U= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4681] Fortran: NULL pointer dereference while parsing a function [PR107423] X-Act-Checkin: gcc X-Git-Author: Steve Kargl X-Git-Refname: refs/heads/master X-Git-Oldrev: 69ec1e2065ac43eea44fdfa703cf027ce72a62da X-Git-Newrev: 531ca06c007d4c4d156637083dcad7f25ac8713d Message-Id: <20221213180910.930CC383AB6E@sourceware.org> Date: Tue, 13 Dec 2022 18:09:10 +0000 (GMT) List-Id: https://gcc.gnu.org/g:531ca06c007d4c4d156637083dcad7f25ac8713d commit r13-4681-g531ca06c007d4c4d156637083dcad7f25ac8713d Author: Steve Kargl Date: Mon Dec 12 21:11:07 2022 +0100 Fortran: NULL pointer dereference while parsing a function [PR107423] gcc/fortran/ChangeLog: PR fortran/107423 * parse.cc (parse_spec): Avoid NULL pointer dereference when parsing a function and an error occured. gcc/testsuite/ChangeLog: PR fortran/107423 * gfortran.dg/pr107423.f90: New test. Diff: --- gcc/fortran/parse.cc | 2 +- gcc/testsuite/gfortran.dg/pr107423.f90 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index cdae43fa1fd..bc2b2188eea 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -4015,7 +4015,7 @@ parse_spec (gfc_statement st) gfc_symbol* proc = gfc_current_ns->proc_name; gcc_assert (proc); - if (proc->result->ts.type == BT_UNKNOWN) + if (proc->result && proc->result->ts.type == BT_UNKNOWN) function_result_typed = true; } diff --git a/gcc/testsuite/gfortran.dg/pr107423.f90 b/gcc/testsuite/gfortran.dg/pr107423.f90 new file mode 100644 index 00000000000..9ae64c94ae0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107423.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-std=f95" } +! PR fortran/107423 - ICE in parse_spec +! Contributed by G.Steinmetz + +program p + type t(k) + integer, kind :: k ! { dg-error "Fortran 2003" } + integer :: a + end type +contains + function f() + type(t(4)), allocatable :: x ! { dg-error "Invalid character" } + allocate (t(4) :: x) ! { dg-error "cannot be used" } + end ! { dg-error "END" } +end ! { dg-error "END" } + +! { dg-prune-output "Unexpected end of file" }