Affects versions down to at least r5 : $ cat z1.f90 module m type t contains final :: s end type contains subroutine s(*) end end $ gfortran-12-20220213 -c z1.f90 f951: internal compiler error: Segmentation fault 0xcc8a9f crash_signal ../../gcc/toplev.cc:322 0x75abf3 gfc_resolve_finalizers ../../gcc/fortran/resolve.cc:13646 0x7726fd resolve_fl_derived ../../gcc/fortran/resolve.cc:15112 0x76c1f7 resolve_symbol ../../gcc/fortran/resolve.cc:15504 0x78b442 do_traverse_symtree ../../gcc/fortran/symbol.cc:4174 0x76f7a4 resolve_types ../../gcc/fortran/resolve.cc:17454 0x76ac3c gfc_resolve(gfc_namespace*) ../../gcc/fortran/resolve.cc:17569 0x752d72 gfc_parse_file() ../../gcc/fortran/parse.cc:6792 0x7a066f gfc_be_parse_file ../../gcc/fortran/f95-lang.cc:216
Self explanatory. diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 835a4783718..1e7c3a07d0e 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -13643,6 +13653,13 @@ gfc_resolve_finalizers (gfc_symbol* derived, bool *finalizable) } arg = dummy_args->sym; + if (!arg) + { + gfc_error ("Argument of FINAL procedure at %L cannot be an " + "alternate return", &list->proc_sym->declared_at); + goto error; + } + /* This argument must be of our type. */ if (arg->ts.type != BT_DERIVED || arg->ts.u.derived != derived) {
(In reply to kargl from comment #1) > Self explanatory. > > diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc Yes. Either this or: @@ -13986,6 +13995,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)) {
On Tue, Mar 21, 2023 at 09:02:14PM +0000, anlauf at gcc dot gnu.org wrote: > --- Comment #2 from anlauf at gcc dot gnu.org --- > (In reply to kargl from comment #1) > > Self explanatory. > > > > diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc > > Yes. Either this or: I'm fine with gfortran emitting either error message. As we've both put eyes on the bug, go ahead and use your error message and commit.
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:3e791f45ded89626bc1f9f8013728f6e035801b2 commit r13-6812-g3e791f45ded89626bc1f9f8013728f6e035801b2 Author: Harald Anlauf <anlauf@gmx.de> Date: Wed Mar 22 19:20:41 2023 +0100 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>
(In reply to Steve Kargl from comment #3) > I'm fine with gfortran emitting either error message. > As we've both put eyes on the bug, go ahead and use > your error message and commit. When using -std=f2018, the new testcase emits: gcc/testsuite/gfortran.dg/pr104572.f90:12:17: 12 | subroutine s(*) ! { dg-error "Argument of FINAL procedure" } | 1 Warning: Obsolescent feature: Alternate-return argument at (1) gcc/testsuite/gfortran.dg/pr104572.f90:12:14: 12 | subroutine s(*) ! { dg-error "Argument of FINAL procedure" } | 1 Error: Argument of FINAL procedure at (1) must be of type 't' The error message is also close to that emitted by other brands. *** Closing.