Bug 40427 - [F03] Procedure Pointer Components with OPTIONAL arguments
[F03] Procedure Pointer Components with OPTIONAL arguments
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.5.0
: P3 normal
: ---
Assigned To: janus
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-06-12 13:14 UTC by janus
Modified: 2009-06-24 11:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-06-13 11:33:42


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-06-12 13:14:42 UTC
The following was reported by John McFarland:

PROGRAM prog

 ABSTRACT INTERFACE
 SUBROUTINE sub_template(i,j,o)
   INTEGER, INTENT(in) :: i
   INTEGER, INTENT(in), OPTIONAL :: j, o
 END SUBROUTINE sub_template
 END INTERFACE

 TYPE container
   PROCEDURE(sub_template), POINTER, NOPASS :: s
 END TYPE container

 PROCEDURE(sub_template), POINTER :: s
 TYPE (container) :: c

 c%s => sub
 s => sub

 CALL callf(s)

 CALL callfc(c)

CONTAINS

 SUBROUTINE callfc(c)
   TYPE (container) :: c

   PRINT*, 'Calling with ppc'
   CALL c%s(1,o=3)
 END SUBROUTINE callfc

 SUBROUTINE callf(f)
   PROCEDURE(sub_template), OPTIONAL, POINTER :: f

   PRINT*, 'Calling pp argument'
   CALL f(1,o=5)
 END SUBROUTINE callf

 SUBROUTINE sub(i,arg2,arg3)
   INTEGER, INTENT(in) :: i
   INTEGER, INTENT(in), OPTIONAL :: arg2, arg3

   PRINT*, 'i:', i
   PRINT*, 'Present:', PRESENT(arg2), PRESENT(arg3)
   IF (PRESENT(arg2)) PRINT*, 'arg2:', arg2
   IF (PRESENT(arg3)) PRINT*, 'arg3:', arg3
 END SUBROUTINE sub

END PROGRAM prog


This program compiles fine, but produces the output:

 Calling pp argument
 i:           1
 Present: F T
 arg3:           5
 Calling with ppc
 i:           1
 Present: T T
 arg2:           3
 arg3:  -443987883


This means that there is a problem with calling PPCs with optional arguments.
Comment 1 Tobias Burnus 2009-06-19 07:32:30 UTC
Patch by Janus: http://gcc.gnu.org/ml/fortran/2009-06/msg00177.html
(I try to get it reviewed soon.)
Comment 2 janus 2009-06-24 11:00:20 UTC
Subject: Bug 40427

Author: janus
Date: Wed Jun 24 10:59:56 2009
New Revision: 148906

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

	PR fortran/40427
	* gfortran.h (gfc_component): New member 'formal_ns'.
	(gfc_copy_formal_args_ppc,void gfc_ppc_use): New.
	* interface.c (gfc_ppc_use): New function, analogous to
	gfc_procedure_use, but for procedure pointer components.
	* module.c (MOD_VERSION): Bump module version.
	(mio_component): Treat formal arguments.
	(mio_formal_arglist): Changed argument from gfc_symbol to
	gfc_formal_arglist.
	(mio_symbol): Changed argument of mio_formal_arglist.
	* resolve.c (resolve_ppc_call,resolve_expr_ppc): Call gfc_ppc_use,
	to check actual arguments and treat formal args correctly.
	(resolve_fl_derived): Copy formal args of procedure pointer components
	from their interface.
	* symbol.c (gfc_copy_formal_args_ppc): New function, analogous to
	gfc_copy_formal_args, but for procedure pointer components.


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

	PR fortran/40427
	* gfortran.dg/proc_ptr_comp_11.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_11.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 janus 2009-06-24 11:02:43 UTC
Fixed with r148906. Closing.