From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: error recovery handling invalid CLASS variable [PR107899]
Date: Sat, 3 Dec 2022 19:27:46 +0100 [thread overview]
Message-ID: <trinity-76ab7545-a0b1-4fc6-9950-b47d9d13742d-1670092066726@3c-app-gmx-bs55> (raw)
[-- Attachment #1: Type: text/plain, Size: 226 bytes --]
Dear all,
the attached obvious patch fixes a NULL pointer dereference
that occurs with an invalid CLASS argument to DEALLOCATE.
Regtested on x86_64-pc-linux-gnu.
Will commit soon unless there are comments.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107899.diff --]
[-- Type: text/x-patch, Size: 1872 bytes --]
From dfe7f1a06d78f6319ad81f5774dc43fe52e37f45 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Sat, 3 Dec 2022 19:21:07 +0100
Subject: [PATCH] Fortran: error recovery handling invalid CLASS variable
[PR107899]
gcc/fortran/ChangeLog:
PR fortran/107899
* resolve.cc (resolve_deallocate_expr): Avoid NULL pointer dereference
on invalid CLASS variable.
gcc/testsuite/ChangeLog:
PR fortran/107899
* gfortran.dg/pr107899.f90: New test.
---
gcc/fortran/resolve.cc | 2 +-
gcc/testsuite/gfortran.dg/pr107899.f90 | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr107899.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 3396c6ce4a7..75dc4b59105 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -7570,7 +7570,7 @@ resolve_deallocate_expr (gfc_expr *e)
sym = e->symtree->n.sym;
unlimited = UNLIMITED_POLY(sym);
- if (sym->ts.type == BT_CLASS)
+ if (sym->ts.type == BT_CLASS && sym->attr.class_ok && CLASS_DATA (sym))
{
allocatable = CLASS_DATA (sym)->attr.allocatable;
pointer = CLASS_DATA (sym)->attr.class_pointer;
diff --git a/gcc/testsuite/gfortran.dg/pr107899.f90 b/gcc/testsuite/gfortran.dg/pr107899.f90
new file mode 100644
index 00000000000..e47b57b7b91
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107899.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+! PR fortran/107899 - ICE in resolve_deallocate_expr
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ end type
+ class(t), target :: x[:] ! { dg-error "deferred shape" }
+ if (allocated (x)) then ! { dg-error "must be ALLOCATABLE" }
+ deallocate (x) ! { dg-error "must be ALLOCATABLE or a POINTER" }
+ end if
+end
--
2.35.3
next reply other threads:[~2022-12-03 18:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-03 18:27 Harald Anlauf [this message]
2022-12-04 9:11 ` Paul Richard Thomas
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-76ab7545-a0b1-4fc6-9950-b47d9d13742d-1670092066726@3c-app-gmx-bs55 \
--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).