Bug 58023 - [F03] ICE on invalid with bad PPC declaration
Summary: [F03] ICE on invalid with bad PPC declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2013-07-29 22:34 UTC by Andrew Benson
Modified: 2015-01-15 18:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Benson 2013-07-29 22:34:28 UTC
The following causes and ICE using gfortran 4.9.0 (r201320):

module m
  implicit none

  abstract interface
     double precision function mr()
     end function mr
  end interface

  type :: sfd
     procedure(mr), pointer :: mr1
     procedure(mr), pointer :: mr2
  end type sfd

contains

  subroutine go()
    implicit none
    type(sfd):: d

    write (0,*) d%mr2()
    return
  end subroutine go

end module m



$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/home/abenson/Galacticus/Tools --enable-languages=c,c++,fortran --disable-multilib --with-gmp=/home/abenson/Galacticus/Tools
Thread model: posix
gcc version 4.9.0 20130729 (experimental) (GCC) 

$ gfortran -c bug.F90 -o bug.o
bug.F90:10.34:

     procedure(mr), pointer :: mr1
                                  1
Error: Procedure pointer component 'mr1' with PASS at (1) must have at least one argument
f951: internal compiler error: in update_ppc_arglist, at fortran/resolve.c:5346
0x58332a update_ppc_arglist
        ../../gcc-trunk/gcc/fortran/resolve.c:5346
0x57f63c resolve_expr_ppc
        ../../gcc-trunk/gcc/fortran/resolve.c:6020
0x57f63c gfc_resolve_expr(gfc_expr*)
        ../../gcc-trunk/gcc/fortran/resolve.c:6119
0x5860bb resolve_code
        ../../gcc-trunk/gcc/fortran/resolve.c:9692
0x585e0b gfc_resolve_blocks(gfc_code*, gfc_namespace*)
        ../../gcc-trunk/gcc/fortran/resolve.c:9006
0x586099 resolve_code
        ../../gcc-trunk/gcc/fortran/resolve.c:9682
0x588c8e resolve_codes
        ../../gcc-trunk/gcc/fortran/resolve.c:14471
0x588b97 resolve_codes
        ../../gcc-trunk/gcc/fortran/resolve.c:14457
0x588d72 gfc_resolve
        ../../gcc-trunk/gcc/fortran/resolve.c:14499
0x5755bf gfc_parse_file()
        ../../gcc-trunk/gcc/fortran/parse.c:4645
0x5b1545 gfc_be_parse_file
        ../../gcc-trunk/gcc/fortran/f95-lang.c:189
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

The code is invalid because both procedure pointers in the "sfd" derived type should have the NOPASS attribute (since the "mr" abstract interface declares no arguments). 

The ICE only occurs if two (or more) procedure points are declared in this way, AND the procedure pointer is accessed (via the write statement in this example).
Comment 1 janus 2013-07-30 08:38:14 UTC
Confirmed. The same ICE occurs on this variant:


  implicit none

  type :: sfd
    procedure(mr), pointer :: mr2
  end type

  type(sfd):: d
  print *, d%mr2()

end
Comment 2 janus 2013-07-30 09:17:45 UTC
Draft patch:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 201283)
+++ gcc/fortran/resolve.c	(working copy)
@@ -12043,9 +12043,11 @@ resolve_fl_derived0 (gfc_symbol *sym)
 	{
 	  gfc_symbol *ifc = c->ts.interface;
 
-	  if (!sym->attr.vtype
-	      && !check_proc_interface (ifc, &c->loc))
-	    return false;
+	  if (!sym->attr.vtype && !check_proc_interface (ifc, &c->loc))
+	    {
+	      c->tb->error = 1;
+	      return false;
+	    }
 
 	  if (ifc->attr.if_source || ifc->attr.intrinsic)
 	    {
Comment 3 janus 2013-07-30 13:08:25 UTC
(In reply to janus from comment #2)
> Draft patch:

Regtests cleanly. Will commit as obvious.
Comment 4 janus 2013-07-30 17:32:56 UTC
(In reply to janus from comment #2)
> Draft patch:

Unfortunately, this patch only fixes comment 1, but not comment 0!
Comment 5 janus 2013-07-30 17:49:04 UTC
Comment 0 can be fixed by the following additional hunk in resolve.c:


@@ -12148,7 +12147,7 @@ resolve_fl_derived0 (gfc_symbol *sym)
                             "must have at least one argument",
                             c->name, &c->loc);
                  c->tb->error = 1;
-                 return false;
+                 continue;
                }
              me_arg = c->ts.interface->formal->sym;
            }
Comment 6 janus 2015-01-11 19:13:57 UTC
Author: janus
Date: Sun Jan 11 19:13:24 2015
New Revision: 219439

URL: https://gcc.gnu.org/viewcvs?rev=219439&root=gcc&view=rev
Log:
2015-01-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58023
	* resolve.c (resolve_fl_derived0): Set error flag if problems with the
	interface of a procedure-pointer component were detected.

2015-01-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58023
	* gfortran.dg/proc_ptr_comp_42.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_42.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2015-01-11 19:32:13 UTC
I have finally committed the patch in comment 2 (sorry that it took so long).

The ICE on comment 0 is still there, but for consistency one should do a bit more than shown in comment 5. Will take care of that next.
Comment 8 janus 2015-01-15 18:28:38 UTC
Author: janus
Date: Thu Jan 15 18:28:02 2015
New Revision: 219676

URL: https://gcc.gnu.org/viewcvs?rev=219676&root=gcc&view=rev
Log:
2015-01-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58023
	* resolve.c (resolve_fl_derived0): Continue resolving next component
	after error.

2015-01-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58023
	* gfortran.dg/proc_ptr_comp_43.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_43.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 janus 2015-01-15 18:34:07 UTC
r219676 fixes the remaining problem with comment 0. Closing.