Bug 37254 - Reject valid PROCEDURE statement with implicit interface
Reject valid PROCEDURE statement with implicit interface
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.4.0
: P3 normal
: ---
Assigned To: janus
: rejects-valid
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-08-27 10:53 UTC by Dominique d'Humieres
Modified: 2009-06-23 07:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-06-22 21:08:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2008-08-27 10:53:48 UTC
 
Comment 1 Dominique d'Humieres 2008-08-27 11:00:30 UTC
Hit return too early!-(

The following code

module myMod
  CONTAINS
  real function proc3( arg1 )
     integer :: arg1
     proc3 = arg1+7
  end function proc3
  subroutine proc4( arg1 )
!     real, external :: arg1
     procedure(real), pointer :: arg1
     print*, 'the func: ', arg1(0)
  end subroutine proc4
  end module myMod

  program myProg
     use myMod
     PROCEDURE (), POINTER :: p => NULL()
     p => proc3
!     print*, 'the func: ', p(0)
     call proc4( p )
  end program myProg

is rejected with:

[ibook-dhum] f90/bug% gfc pointer_subs_red.f90
pointer_subs_red.f90:19.16:

     call proc4( p )
               1
Error: Type/rank mismatch in argument 'arg1' at (1)

It is accepted if I uncomment the second commented line, but leads to PR27253.

Additional question: is it valid to replace

procedure(real), pointer :: arg1

with

real, external :: arg1

? Janus Weil says no and the changed code gives the same error as the original one.

Comment 2 Dominique d'Humieres 2008-08-27 11:05:33 UTC
s/to PR27253./to PR37253./
Comment 3 janus 2008-08-27 19:52:19 UTC
Also the following version of Dominique's test case gives the same error, using PROCEDURE statements without the POINTER attribute:

  real function proc3( arg1 )
     integer :: arg1
     proc3 = arg1+7
  end function proc3

program myProg
  PROCEDURE () :: proc3
  call proc4( proc3 )
  
  CONTAINS

  subroutine proc4( arg1 )
     PROCEDURE(real) :: arg1
     print*, 'the func: ', arg1(0)
  end subroutine proc4

end program myProg

The error also appears for PROCEDURE() :: arg1. It goes away, however, if proc3 is declared as PROCEDURE(real), regardless of whether arg1 has an explicit or implicit return type.
Comment 4 Dominique d'Humieres 2008-08-28 09:33:26 UTC
It seems that some "attribute(s)" is(are) not properly (re)set.  The following code 

module myMod
  CONTAINS
  subroutine proc1(arg1, arg2, arg3)
     integer :: arg1, arg2, arg3
     print*, arg1, arg2, arg3, 's ', arg1+arg2+arg3
  end subroutine proc1
  subroutine proc2(arg1, arg2, arg3)
     integer :: arg1, arg2, arg3
     print*, arg1, arg2, arg3, 'p ', arg1*arg2*arg3
  end subroutine proc2
  real function proc3( arg1 )
     integer :: arg1
     proc3 = arg1+7
  end function proc3
  subroutine proc4( arg1 )
     real, external :: arg1
     print*, 'the func: ', arg1(0)
  end subroutine proc4
  end module myMod

  program myProg
     use myMod
     PROCEDURE (), POINTER :: p => NULL()
     p => proc1
!1     call p(0, 2, 3)
     p => proc2
!2     call p(0, 2, 3)
     p => proc3
!3     call proc4( p )
!4     print*, 'the func: ', p(0)   ! "Unexpected array reference"
  end program myProg

compiles without error. If I remove the comments 1 to 4, I get the errors:

pointer_subs.f90:30.31:

     print*, 'the func: ', p(0)   ! "Unexpected array reference"
                              1
Error: FUNCTION attribute conflicts with SUBROUTINE attribute in 'p' at (1)
pointer_subs.f90:29.16:

     call proc4( p )
               1
Error: Type/rank mismatch in argument 'arg1' at (1)

If I remove comments 1 and 2 or comments 3 and 4, the program compiles without error and gives at run time respectively (after having applied the fix for pr37253):

[ibook-dhum] f90/bug% a.out
           0           2           3 s            5
           0           2           3 p            0
[ibook-dhum] f90/bug% a.out
 the func:    7.0000000    
 the func:    7.0000000    
Comment 5 Dominique d'Humieres 2008-08-28 13:05:46 UTC
Grepping the sources it seems that the value of ??->intent associated with 'p' is not reset to INTENT_UNKNOWN on "p => new_proc".
Comment 6 janus 2008-11-30 12:28:02 UTC
I'm not sure the codes in comment #1 and #3 are actually valid, or if gfortran is right to reject them. See also PR33162 comment #9, where Jerry concludes that a similar thing should be rejected (this is proc_decl_8.f90 is the testsuite).
Comment 8 janus 2009-06-22 21:02:42 UTC
Subject: Bug 37254

Author: janus
Date: Mon Jun 22 21:02:19 2009
New Revision: 148816

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148816
Log:
2009-06-22  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/37254
	PR fortran/39850
	* interface.c (compare_parameter): Set implicit type for function
	actual arguments with BT_UNKNOWN.


2009-06-22  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/37254
	PR fortran/39850
	* gfortran.dg/interface_30.f90: Modified error message.
	* gfortran.dg/proc_decl_22.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_decl_22.f90   (with props)
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/interface_30.f90

Propchange: trunk/gcc/testsuite/gfortran.dg/proc_decl_22.f90
            ('svn:executable' added)


Comment 9 janus 2009-06-22 21:08:50 UTC
r148816 fixes comment #1 and #3.

The errors in comment #4 are justified, since subroutines and functions are mixed.

So I think this can be closed if there are no further problems.
Comment 10 janus 2009-06-22 21:28:46 UTC
Subject: Bug 37254

Author: janus
Date: Mon Jun 22 21:28:34 2009
New Revision: 148817

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148817
Log:

2009-06-22  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/37254
	* gfortran.dg/proc_decl_22.f90: Delete property svn:executable
	(wrongly introduced in last commit).


Modified:
    trunk/gcc/testsuite/gfortran.dg/proc_decl_22.f90   (props changed)

Propchange: trunk/gcc/testsuite/gfortran.dg/proc_decl_22.f90
            ('svn:executable' removed)


Comment 11 janus 2009-06-23 07:27:16 UTC
Closing.