From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: NULL pointer dereference while parsing a function [PR107423]
Date: Mon, 12 Dec 2022 21:22:12 +0100 [thread overview]
Message-ID: <trinity-7efcc196-d97a-4fa6-bd76-48e9eb90d528-1670876532663@3c-app-gmx-bs69> (raw)
[-- Attachment #1: Type: text/plain, Size: 222 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107423.diff --]
[-- Type: text/x-patch, Size: 1934 bytes --]
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
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" }
--
2.35.3
reply other threads:[~2022-12-12 20:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-7efcc196-d97a-4fa6-bd76-48e9eb90d528-1670876532663@3c-app-gmx-bs69 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).