Bug 44718 - Procedure-pointer name is wrongly regarded as "external procedure"
Summary: Procedure-pointer name is wrongly regarded as "external procedure"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-06-29 18:32 UTC by Tobias Burnus
Modified: 2010-06-29 21:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-29 19:31:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-06-29 18:32:20 UTC
Reported by John McFarland at http://gcc.gnu.org/ml/fortran/2010-06/msg00286.html

If one uses
  procedure(<interface>), pointer :: f
at multiple scopes of the same program, gfortran treats the proc-pointer name ("f") as external name - and thus rejects using it once as function and once as subroutine name:

Error: Global name 'f' at (1) is already being used as a SUBROUTINE at (2)


Test case by John McFarland:

MODULE m
  IMPLICIT NONE
CONTAINS
  FUNCTION func(x) RESULT(y)
    INTEGER :: x,y
    y = x *2
  END FUNCTION func

  SUBROUTINE sub(x)
    INTEGER :: x
    PRINT*, x
  END SUBROUTINE sub

  SUBROUTINE use_func()
    PROCEDURE(func), POINTER :: f
    INTEGER :: y
    f => func
    y = f(2)
  END SUBROUTINE use_func

  SUBROUTINE use_sub()
    PROCEDURE(sub), POINTER :: f
    f => sub
    CALL f(2)
  END SUBROUTINE use_sub
END MODULE m
Comment 1 janus 2010-06-29 19:31:11 UTC
The following patch fixes it:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 161551)
+++ gcc/fortran/resolve.c	(working copy)
@@ -2259,6 +2259,7 @@ is_external_proc (gfc_symbol *sym)
 	&& !(sym->attr.intrinsic
 	      || gfc_is_intrinsic (sym, sym->attr.subroutine, sym->declared_at))
 	&& sym->attr.proc != PROC_ST_FUNCTION
+	&& !sym->attr.proc_pointer
 	&& !sym->attr.use_assoc
 	&& sym->name)
     return true;


Regtesting now ...
Comment 2 janus 2010-06-29 20:24:54 UTC
(In reply to comment #1)
> Regtesting now ...

... finished successfully.
Comment 3 janus 2010-06-29 21:40:54 UTC
Subject: Bug 44718

Author: janus
Date: Tue Jun 29 21:40:38 2010
New Revision: 161569

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

	PR fortran/44718
	* resolve.c (is_external_proc): Prevent procedure pointers from being
	regarded as external procedures.

2010-06-29  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44718
	* gfortran.dg/proc_ptr_28.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_28.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 janus 2010-06-29 21:43:21 UTC
Fixed with r161569. Closing.