[committed] Fortran: improve checking of FINAL subroutine arguments [PR104572]
Checks
Commit Message
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
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
@@ -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))
{
new file mode 100644
@@ -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