* [PATCH] Fortran: error recovery after reference to bad CLASS variable [PR107681]
@ 2022-11-16 20:50 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-11-16 20:50 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
Dear all,
the attached obvious patch fixes a NULL pointer dereference
when referencing a CLASS variable with a bad decl.
Pushed as r13-4107-g96e4244ef3ccf4867ca4e37fbc6800e64ef30af6
after regtesting on x86_64-pc-linux-gnu.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107681.diff --]
[-- Type: text/x-patch, Size: 1848 bytes --]
From 96e4244ef3ccf4867ca4e37fbc6800e64ef30af6 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 16 Nov 2022 21:41:19 +0100
Subject: [PATCH] Fortran: error recovery after reference to bad CLASS variable
[PR107681]
gcc/fortran/ChangeLog:
PR fortran/107681
* resolve.cc (resolve_fl_var_and_proc): Prevent NULL pointer
dereference with reference to bad CLASS variable.
gcc/testsuite/ChangeLog:
PR fortran/107681
* gfortran.dg/pr107681.f90: New test.
---
gcc/fortran/resolve.cc | 1 +
gcc/testsuite/gfortran.dg/pr107681.f90 | 13 +++++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr107681.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 5ff1cd070ac..24e5aa03556 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -12967,6 +12967,7 @@ resolve_fl_var_and_proc (gfc_symbol *sym, int mp_flag)
&& sym->ts.u.derived
&& !sym->attr.select_type_temporary
&& !UNLIMITED_POLY (sym)
+ && CLASS_DATA (sym)->ts.u.derived
&& !gfc_type_is_extensible (CLASS_DATA (sym)->ts.u.derived))
{
gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
diff --git a/gcc/testsuite/gfortran.dg/pr107681.f90 b/gcc/testsuite/gfortran.dg/pr107681.f90
new file mode 100644
index 00000000000..0999ad92649
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107681.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+! PR fortran/107681 - ICE in gfc_type_is_extensible
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ integer, allocatable :: a
+ end type
+ class(t) :: x[*] ! { dg-error "must be dummy, allocatable or pointer" }
+ associate (y => x) ! { dg-error "Invalid array reference" }
+ end associate
+end
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-16 20:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 20:50 [PATCH] Fortran: error recovery after reference to bad CLASS variable [PR107681] 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).