public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR42045: [F03] passing a procedure pointer component   to a procedure pointer dummy
@ 2009-11-22  1:48 Janus Weil
  2009-11-23 22:12 ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Janus Weil @ 2009-11-22  1:48 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

Hi all,

this patch fixes some trouble with PPCs which have no interface [i.e.
"procedure()"]. Up to now, what we did with these was to apply
implicit typing. However, Malcolm Cohen's draft answer to an
interpretation request by Tobias
(http://www.j3-fortran.org/doc/year/09/09-236r1.txt) states that PPCs
should never be implicitly typed. Due to this reasoning, a PPC without
explicit interface specification can only be a subroutine pointer (and
not a function pointer).

The patch also fixes the problem that John McFarland reported (which
was caused by the implicit typing of PPCs). It was regtested
successfully on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2009-11-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42045
	* resolve.c (resolve_actual_arglist): Make sure procedure pointer
	actual arguments are resolved correctly.
	(resolve_function): An EXPR_FUNCTION which is a procedure pointer
	component, has already been resolved.
	(resolve_fl_derived): Procedure pointer components should not be
	implicitly typed.

2009-11-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42045
	* gfortran.dg/proc_ptr_comp_2.f90: Correct invalid test case.
	* gfortran.dg/proc_ptr_comp_3.f90: Extended test case.
	* gfortran.dg/proc_ptr_comp_24.f90: New.

[-- Attachment #2: pr42045.diff --]
[-- Type: text/x-diff, Size: 2799 bytes --]

Index: gcc/testsuite/gfortran.dg/proc_ptr_comp_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_ptr_comp_2.f90	(revision 154409)
+++ gcc/testsuite/gfortran.dg/proc_ptr_comp_2.f90	(working copy)
@@ -9,7 +9,6 @@
   type t
     procedure(fcn), pointer, nopass :: ppc
     procedure(abstr), pointer, nopass :: ppc1
-    procedure(), nopass, pointer:: iptr3
     integer :: i
   end type
 
@@ -43,11 +42,6 @@
   if (base/=12) call abort
   call foo (f,7)
 
-! Check with implicit interface
-  obj%iptr3 => iabs
-  base=obj%iptr3(-9)
-  if (base/=9) call abort
-
 contains
 
   integer function fcn(x)
Index: gcc/testsuite/gfortran.dg/proc_ptr_comp_3.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_ptr_comp_3.f90	(revision 154409)
+++ gcc/testsuite/gfortran.dg/proc_ptr_comp_3.f90	(working copy)
@@ -16,6 +16,7 @@ end interface
 external :: aaargh
 
 type :: t
+  procedure(), pointer, nopass :: ptr1
   procedure(real), pointer, nopass :: ptr2
   procedure(sub), pointer, nopass :: ptr3
   procedure(), pointer, nopass ptr4              ! { dg-error "Expected '::'" }
@@ -40,6 +41,7 @@ x%ptr2 => x       ! { dg-error "Invalid procedure
 
 x => x%ptr2       ! { dg-error "Pointer assignment to non-POINTER" }
 
+print *, x%ptr1() ! { dg-error "attribute conflicts with" }
 call x%ptr2()     ! { dg-error "attribute conflicts with" }
 print *,x%ptr3()  ! { dg-error "attribute conflicts with" }
 
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 154409)
+++ gcc/fortran/resolve.c	(working copy)
@@ -1321,6 +1321,8 @@ resolve_actual_arglist (gfc_actual_arglist *arg, p
 		e->rank = comp->as->rank;
 	      e->expr_type = EXPR_FUNCTION;
 	    }
+	  if (gfc_resolve_expr (e) == FAILURE)                          
+	    return FAILURE; 
 	  goto argument_list;
 	}
 
@@ -2519,6 +2521,10 @@ resolve_function (gfc_expr *expr)
   if (expr->symtree)
     sym = expr->symtree->n.sym;
 
+  /* If this is a procedure pointer component, it has already been resolved.  */
+  if (gfc_is_proc_ptr_comp (expr, NULL))
+    return SUCCESS;
+  
   if (sym && sym->attr.intrinsic
       && resolve_intrinsic (sym, &expr->where) == FAILURE)
     return FAILURE;
@@ -10219,8 +10225,9 @@ resolve_fl_derived (gfc_symbol *sym)
 	}
       else if (c->attr.proc_pointer && c->ts.type == BT_UNKNOWN)
 	{
-	  c->ts = *gfc_get_default_type (c->name, NULL);
-	  c->attr.implicit_type = 1;
+	  /* Since PPCs are not implicitly typed, a PPC without an explicit
+	     interface must be a subroutine.  */
+	  gfc_add_subroutine (&c->attr, c->name, &c->loc);
 	}
 
       /* Procedure pointer components: Check PASS arg.  */

[-- Attachment #3: proc_ptr_comp_24.f90 --]
[-- Type: application/octet-stream, Size: 656 bytes --]

! { dg-do compile }
!
! PR42045: [F03] passing a procedure pointer component to a procedure pointer dummy
!
! Contributed by John McFarland <john.mcfarland@swri.org>

PROGRAM prog
 TYPE object
  PROCEDURE(), POINTER, NOPASS :: f
 END TYPE object
 TYPE container
  TYPE (object), POINTER :: o(:)
 END TYPE container
 TYPE (container) :: c
 TYPE (object) :: o1, o2
 PROCEDURE(), POINTER :: f => NULL()
 o1%f => f
 CALL set_func(o2,f)
 CALL set_func(o2,o1%f)
 ALLOCATE( c%o(5) )
 c%o(5)%f => f
 CALL set_func(o2,c%o(5)%f)
CONTAINS
 SUBROUTINE set_func(o,f)
  TYPE (object) :: o
  PROCEDURE(), POINTER :: f
  o%f => f
 END SUBROUTINE set_func
END PROGRAM prog

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] PR42045: [F03] passing a procedure pointer component    to a procedure pointer dummy
  2009-11-22  1:48 [Patch, Fortran] PR42045: [F03] passing a procedure pointer component to a procedure pointer dummy Janus Weil
@ 2009-11-23 22:12 ` Tobias Burnus
  2009-11-24  8:30   ` Janus Weil
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2009-11-23 22:12 UTC (permalink / raw)
  To: Janus Weil; +Cc: gfortran, gcc-patches

Janus Weil wrote:
> The patch also fixes the problem that John McFarland reported (which
> was caused by the implicit typing of PPCs). It was regtested
> successfully on x86_64-unknown-linux-gnu. Ok for trunk?
>   
OK. Thanks for the patch!

Tobias

> 2009-11-21  Janus Weil  <janus@gcc.gnu.org>
>
> 	PR fortran/42045
> 	* resolve.c (resolve_actual_arglist): Make sure procedure pointer
> 	actual arguments are resolved correctly.
> 	(resolve_function): An EXPR_FUNCTION which is a procedure pointer
> 	component, has already been resolved.
> 	(resolve_fl_derived): Procedure pointer components should not be
> 	implicitly typed.
>
> 2009-11-21  Janus Weil  <janus@gcc.gnu.org>
>
> 	PR fortran/42045
> 	* gfortran.dg/proc_ptr_comp_2.f90: Correct invalid test case.
> 	* gfortran.dg/proc_ptr_comp_3.f90: Extended test case.
> 	* gfortran.dg/proc_ptr_comp_24.f90: New.
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] PR42045: [F03] passing a procedure pointer   component to a procedure pointer dummy
  2009-11-23 22:12 ` Tobias Burnus
@ 2009-11-24  8:30   ` Janus Weil
  0 siblings, 0 replies; 3+ messages in thread
From: Janus Weil @ 2009-11-24  8:30 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gfortran, gcc-patches

>> The patch also fixes the problem that John McFarland reported (which
>> was caused by the implicit typing of PPCs). It was regtested
>> successfully on x86_64-unknown-linux-gnu. Ok for trunk?
>>
> OK. Thanks for the patch!

Thanks. Committed as r154492.

Cheers,
Janus


>> 2009-11-21  Janus Weil  <janus@gcc.gnu.org>
>>
>>       PR fortran/42045
>>       * resolve.c (resolve_actual_arglist): Make sure procedure pointer
>>       actual arguments are resolved correctly.
>>       (resolve_function): An EXPR_FUNCTION which is a procedure pointer
>>       component, has already been resolved.
>>       (resolve_fl_derived): Procedure pointer components should not be
>>       implicitly typed.
>>
>> 2009-11-21  Janus Weil  <janus@gcc.gnu.org>
>>
>>       PR fortran/42045
>>       * gfortran.dg/proc_ptr_comp_2.f90: Correct invalid test case.
>>       * gfortran.dg/proc_ptr_comp_3.f90: Extended test case.
>>       * gfortran.dg/proc_ptr_comp_24.f90: New.
>>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-24  8:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-22  1:48 [Patch, Fortran] PR42045: [F03] passing a procedure pointer component to a procedure pointer dummy Janus Weil
2009-11-23 22:12 ` Tobias Burnus
2009-11-24  8:30   ` Janus Weil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).