public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, committed] Fortran: improve checking of FINAL subroutine arguments [PR104572]
Date: Wed, 22 Mar 2023 19:30:23 +0100	[thread overview]
Message-ID: <trinity-7df2d884-20c1-4801-a213-d2e676f4dafd-1679509823088@3c-app-gmx-bap55> (raw)

[-- 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


                 reply	other threads:[~2023-03-22 18:30 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-7df2d884-20c1-4801-a213-d2e676f4dafd-1679509823088@3c-app-gmx-bap55 \
    --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).