]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: NULL pointer dereference while parsing a function [PR107423]
authorSteve Kargl <kargl@gcc.gnu.org>
Mon, 12 Dec 2022 20:11:07 +0000 (21:11 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 13 Dec 2022 18:08:23 +0000 (19:08 +0100)
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.

gcc/fortran/parse.cc
gcc/testsuite/gfortran.dg/pr107423.f90 [new file with mode: 0644]

index cdae43fa1fda2e3acd61770db0bfda62e50f6516..bc2b2188eea7f97509770f29d8e7f832a8b66e35 100644 (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;
     }
 
diff --git a/gcc/testsuite/gfortran.dg/pr107423.f90 b/gcc/testsuite/gfortran.dg/pr107423.f90
new file mode 100644 (file)
index 0000000..9ae64c9
--- /dev/null
@@ -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" }