summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kargl <kargl@gcc.gnu.org>2022-12-12 21:11:07 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-12-13 19:08:23 +0100
commit531ca06c007d4c4d156637083dcad7f25ac8713d (patch)
tree26dea60f73957d7a7b559a542d037bb8dee2cebb
parent69ec1e2065ac43eea44fdfa703cf027ce72a62da (diff)
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.
-rw-r--r--gcc/fortran/parse.cc2
-rw-r--r--gcc/testsuite/gfortran.dg/pr107423.f9018
2 files changed, 19 insertions, 1 deletions
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" }