User account creation filtered due to spam.

Bug 38290 - procedure pointer assignment checking
Summary: procedure pointer assignment checking
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2008-11-27 13:44 UTC by Tobias Burnus
Modified: 2009-04-07 07:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-06 12:25:33


Attachments
patch v1 (2.72 KB, patch)
2008-12-06 13:57 UTC, janus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-11-27 13:44:25 UTC
Found at http://de.wikibooks.org/wiki/Fortran:_Fortran_2003:_Zeiger

The following program gives an ICE:

hjff.f90:4.34:

  procedure( up ), pointer :: pptr => null()
                                 1
Error: Interface 'up' of procedure 'pptr' at (1) must be explicit
hjff.f90:4.15:

  procedure( up ), pointer :: pptr => null()
              1
Error: Symbol 'up' at (1) has no IMPLICIT type
f951: internal compiler error: in resolve_specific_s0, at fortran/resolve.c:2758
Please submit a full bug report,



program bsp
  implicit none

  procedure( up ), pointer :: pptr => null()

  pptr => ooops

  call pptr
end program bsp
Comment 1 janus 2008-11-27 22:09:00 UTC
The test case can be further compressed to a 3-liner

procedure( up ) :: p
call p
end

and is fixed by the following simple patch

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 142171)
+++ gcc/fortran/resolve.c	(working copy)
@@ -2748,7 +2748,8 @@ resolve_specific_s0 (gfc_code *c, gfc_sy
 
   /* See if we have an intrinsic interface.  */
   if (sym->ts.interface != NULL && !sym->ts.interface->attr.abstract
-      && !sym->ts.interface->attr.subroutine)
+      && !sym->ts.interface->attr.subroutine
+      && sym->ts.interface->attr.intrinsic)
     {
       gfc_intrinsic_sym *isym;
Comment 2 janus 2008-11-27 22:50:27 UTC
I also tried to compile the other procptr examples from the WikiBooks page, which is linked in comment #0.

The only remaining problem I found was:

program bsp
  implicit none   

  abstract interface
    subroutine up()
    end subroutine up
  end interface

  procedure( up ) , pointer :: pptr

  pptr => add  
     
  contains
    
    function add( a, b )
      integer               :: add
      integer, intent( in ) :: a, b
      add = a + b
    end function add

end program bsp

This is currently accepted by gfortran, although invalid, and is rejected e.g. by ifort with

error #8179: The procedure pointer and the procedure target must both be functions or subroutines.

Inserting a statement like

  print *, pptr()

produces an ICE.
Comment 3 janus 2008-11-29 13:38:00 UTC
Subject: Bug 38290

Author: janus
Date: Sat Nov 29 13:36:35 2008
New Revision: 142276

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142276
Log:
2008-11-29  Janus Weil  <janus@gcc.gnu.org>
	    Mikael Morin <mikael@gcc.gnu.org>

	PR fortran/38289
	PR fortran/38290
	* decl.c (match_procedure_decl): Handle whitespaces.
	* resolve.c (resolve_specific_s0): Bugfix in check for intrinsic
	interface.


2008-11-29  Janus Weil  <janus@gcc.gnu.org>
	    Tobias Burnus <burnus@gcc.gnu.org>

	PR fortran/38289
	PR fortran/38290
	* gfortran.dg/proc_decl_1.f90: Extended test case.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/proc_decl_1.f90

Comment 4 janus 2008-12-02 11:59:39 UTC
Subject: Bug 38290

Author: janus
Date: Tue Dec  2 11:58:16 2008
New Revision: 142351

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142351
Log:
2008-12-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	PR fortran/38290
	* decl.c (match_result): Result may be a standard variable or a
	procedure pointer.
	* expr.c (gfc_check_pointer_assign): Additional checks for procedure
	pointer assignments.
	* primary.c (gfc_match_rvalue): Bugfix for procedure pointer
	assignments.
	* resolve.c (resolve_function): Check for attr.subroutine.
	* symbol.c (check_conflict): Addtional checks for RESULT statements.
	* trans-types.c (gfc_sym_type,gfc_get_function_type): Support procedure
	pointers as function result.


2008-12-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	PR fortran/38290
	* gfortran.dg/entry_7.f90: Modified.
	* gfortran.dg/proc_ptr_2.f90: Extended.
	* gfortran.dg/proc_ptr_3.f90: Modified.
	* gfortran.dg/proc_ptr_11.f90: New.
	* gfortran.dg/proc_ptr_12.f90: New.
	* gfortran.dg/result_1.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_11.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_12.f90
    trunk/gcc/testsuite/gfortran.dg/result_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/entry_7.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_2.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_3.f90

Comment 5 janus 2008-12-02 12:02:00 UTC
Fixed with r142351. Closing.
Comment 6 janus 2008-12-06 12:23:56 UTC
Reopening. The check for comparing the interfaces was taken out again in r142520, since there were problems with intrinsics. Details will follow.
Comment 7 Tobias Burnus 2008-12-06 12:25:33 UTC
Check backed out in PR 38415, cf.
http://gcc.gnu.org/ml/fortran/2008-12/msg00089.html

"I'm afraid I'll have to remove the gfc_compare_interfaces check in
 gfc_check_pointer_assign again, since I just noticed that it has lots
 of problems with intrinsics (both in lvalue and rvalue)"
Comment 8 janus 2008-12-06 13:57:27 UTC
Created attachment 16841 [details]
patch v1

Here is a draft patch which correctly copies the typespec and formal args for a PROCEDURE statement with INTRINSIC interface. It also makes gfc_compare_interfaces work with intrinsics and re-enables the interface check for procedure pointer assignments.

Stuff like the following should work now:

procedure(iabs),pointer::p1
procedure(f), pointer::p2

! valid
p1 => iabs
p2 => iabs
p1 => f
p2 => f
p2 => p1
p1 => p2

! invalid
p1 => abs
p2 => abs

contains

  integer function f(x)
    integer :: x
    f = 317
  end function

end
Comment 9 janus 2009-03-11 16:23:48 UTC
Patch: http://gcc.gnu.org/ml/fortran/2008-12/msg00191.html
Comment 10 janus 2009-04-07 07:32:10 UTC
Fixed with r145651 (I messed up the PR number in the ChangeLog entry, though). Closing.