public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4681] Fortran: NULL pointer dereference while parsing a function [PR107423]
@ 2022-12-13 18:09 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-12-13 18:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:531ca06c007d4c4d156637083dcad7f25ac8713d

commit r13-4681-g531ca06c007d4c4d156637083dcad7f25ac8713d
Author: Steve Kargl <kargl@gcc.gnu.org>
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" }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-13 18:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 18:09 [gcc r13-4681] Fortran: NULL pointer dereference while parsing a function [PR107423] Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).