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.
This commit is contained in:
Steve Kargl 2022-12-12 21:11:07 +01:00 committed by Harald Anlauf
parent 69ec1e2065
commit 531ca06c00
2 changed files with 19 additions and 1 deletions

View File

@ -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;
}

View File

@ -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" }