Fortran: NULL pointer dereference while parsing a function [PR107423]
Checks
Commit Message
Dear all,
here's another obvious patch by Steve which prevents a
NULL pointer dereference during parsing.
Regtested on x86_64-pc-linux-gnu.
Will commit to mainline within 24h unless there are comments.
Thanks,
Harald
From f23a5252ee086f9b78c44150d409e40a445c6928 Mon Sep 17 00:00:00 2001
From: Steve Kargl <kargl@gcc.gnu.org>
Date: Mon, 12 Dec 2022 21:11:07 +0100
Subject: [PATCH] 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.
---
gcc/fortran/parse.cc | 2 +-
gcc/testsuite/gfortran.dg/pr107423.f90 | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr107423.f90
@@ -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;
}
new file mode 100644
@@ -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" }
--
2.35.3