]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: improve checking of FINAL subroutine arguments [PR104572]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 22 Mar 2023 18:20:41 +0000 (19:20 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 22 Mar 2023 18:20:41 +0000 (19:20 +0100)
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
gcc/testsuite/gfortran.dg/pr104572.f90 [new file with mode: 0644]

index 1a03e458d9931c13c7d5ec2cada369f19a48dafa..f6ec76acb0bb933b34f782675490c81bf9d6e932 100644 (file)
@@ -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 (file)
index 0000000..59fd688
--- /dev/null
@@ -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