* [PATCH, committed] Fortran: improve checking of FINAL subroutine arguments [PR104572]
@ 2023-03-22 18:30 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-03-22 18:30 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 210 bytes --]
Dear all,
I've committed the attached simple patch after discussion with
Steve (see PR). We need to reject alternate return arguments
of FINAL subroutines.
Regtested on x86_64-pc-linux-gnu.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr104572.diff --]
[-- Type: text/x-patch, Size: 1889 bytes --]
From 3e791f45ded89626bc1f9f8013728f6e035801b2 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 22 Mar 2023 19:20:41 +0100
Subject: [PATCH] Fortran: improve checking of FINAL subroutine arguments
[PR104572]
gcc/fortran/ChangeLog:
PR fortran/104572
* resolve.cc (gfc_resolve_finalizers): Argument of a FINAL subroutine
cannot be an alternate return.
gcc/testsuite/ChangeLog:
PR fortran/104572
* gfortran.dg/pr104572.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
---
gcc/fortran/resolve.cc | 7 +++++++
gcc/testsuite/gfortran.dg/pr104572.f90 | 14 ++++++++++++++
2 files changed, 21 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr104572.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 1a03e458d99..f6ec76acb0b 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -13986,6 +13986,13 @@ gfc_resolve_finalizers (gfc_symbol* derived, bool *finalizable)
}
arg = dummy_args->sym;
+ if (!arg)
+ {
+ gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
+ &list->proc_sym->declared_at, derived->name);
+ goto error;
+ }
+
if (arg->as && arg->as->type == AS_ASSUMED_RANK
&& ((list != derived->f2k_derived->finalizers) || list->next))
{
diff --git a/gcc/testsuite/gfortran.dg/pr104572.f90 b/gcc/testsuite/gfortran.dg/pr104572.f90
new file mode 100644
index 00000000000..59fd688d798
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104572.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-additional-options "-w" }
+! PR fortran/104572 - ICE in gfc_resolve_finalizers
+! Contributed by G. Steinmetz
+
+module m
+ type t
+ contains
+ final :: s
+ end type
+contains
+ subroutine s(*) ! { dg-error "Argument of FINAL procedure" }
+ end
+end
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-22 18:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 18:30 [PATCH, committed] Fortran: improve checking of FINAL subroutine arguments [PR104572] 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).