[Patch, Fortran, 4.5 Regression] PR 41139: a procedure pointer call as actual argument

Janus Weil janus@gcc.gnu.org
Sat Aug 22 15:03:00 GMT 2009

Hi all,

this patch fixes three problems:

1) A regression with procedure pointers (comment #2 in the PR,
proc_ptr_24.f90). The corresponding part of the patch is this:

@@ -2679,6 +2696,7 @@ gfc_conv_procedure_call (gfc_se * se, gf
 	      else if (e->expr_type == EXPR_FUNCTION
 		       && e->symtree->n.sym->result
+		       && e->symtree->n.sym->result != e->symtree->n.sym
 		       && e->symtree->n.sym->result->attr.proc_pointer)
 		  /* Functions returning procedure pointers.  */

Functions returning procedure pointers are only uniquely identified by
the fact that they have a separate result variable.


2) A small problem with PPCs as actual arguments (comment #4,
proc_ptr_comp_18.f90), which is fixed by this hunk:

@@ -2695,7 +2713,8 @@ gfc_conv_procedure_call (gfc_se * se, gf
 			  || (fsym->attr.proc_pointer
 			      && !(e->expr_type == EXPR_VARIABLE
 			      && e->symtree->n.sym->attr.dummy))
-			  || gfc_is_proc_ptr_comp (e, NULL)))
+			  || (e->expr_type == EXPR_VARIABLE
+			      && gfc_is_proc_ptr_comp (e, NULL))))
 		      /* Scalar pointer dummy args require an extra level of
 			 indirection. The null pointer already contains

A PPC with EXPR_FUNCTION is a function call to a PPC which is passed
as actual argument.


3) Another problem with PPCs which have no formal arguments (comment
#11, proc_ptr_comp_19.f90). Fixed by these two hunks:

Index: gcc/fortran/resolve.c
--- gcc/fortran/resolve.c	(revision 151009)
+++ gcc/fortran/resolve.c	(working copy)
@@ -1279,9 +1279,7 @@ resolve_actual_arglist (gfc_actual_argli
       if (gfc_is_proc_ptr_comp (e, &comp))
 	  e->ts = comp->ts;
-	  if (e->value.compcall.actual == NULL)
-	    e->expr_type = EXPR_VARIABLE;
-	  else
+	  if (e->expr_type == EXPR_PPC)
 	      if (comp->as != NULL)
 		e->rank = comp->as->rank;
Index: gcc/fortran/primary.c
--- gcc/fortran/primary.c	(revision 151009)
+++ gcc/fortran/primary.c	(working copy)
@@ -1839,13 +1839,12 @@ gfc_match_varspec (gfc_expr *primary, in
       if (component->attr.proc_pointer && ppc_arg
 	  && !gfc_matching_procptr_assignment)
-	  primary->expr_type = EXPR_PPC;
-	  m = gfc_match_actual_arglist (component->attr.subroutine,
+	  m = gfc_match_actual_arglist (sub_flag,
 	  if (m == MATCH_ERROR)
 	    return MATCH_ERROR;
-	  if (m == MATCH_NO)
-	    primary->value.compcall.actual = NULL;
+	  if (m == MATCH_YES)
+	    primary->expr_type = EXPR_PPC;


Here, component->attr.subroutine is not yet set (this only happens at
the resolution stage for PPCs). Also, EXPR_PPC should only used for
calls to PPCs, not for other references (e.g. passing the PPC as
actual argument). In the resolve.c hunk, EXPR_VARIABLE was falsely
used for PPCs with no formal args.


Moreover, the function 'gfc_get_proc_ptr_comp' is made static and renamed.

The patchlets from comments #7/#12 are not included here, since I'm
not sure if they are correct.

Regression-tested on x86_64-unknown-linux-gnu. Ok for trunk?


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

	PR fortran/41139
	* primary.c (gfc_match_varspec): Make sure EXPR_PPC is only used for
	calls to procedure pointer components, other references to procedure
	pointer components are EXPR_VARIABLE.
	* resolve.c (resolve_actual_arglist): Bugfix (there can be calls without
	actual arglist).
	* trans-expr.c (gfc_get_proc_ptr_comp): Renamed to get_proc_ptr_comp
	and made static.
	(conv_function_val): Renamed gfc_get_proc_ptr_comp.
	(gfc_conv_procedure_call): Distinguish functions returning a procedure
	pointer from calls to a procedure pointer. Distinguish calls to
	procedure pointer components from procedure pointer components as
	actual arguments.
	* trans-stmt.h (gfc_get_proc_ptr_comp): Make it static.

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

	PR fortran/41139
	* gfortran.dg/proc_ptr_24.f90: New.
	* gfortran.dg/proc_ptr_comp_18.f90: New.
	* gfortran.dg/proc_ptr_comp_19.f90: New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr41139.diff
Type: text/x-diff
Size: 4043 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090822/861b94f9/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proc_ptr_24.f90
Type: application/octet-stream
Size: 682 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090822/861b94f9/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proc_ptr_comp_18.f90
Type: application/octet-stream
Size: 552 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090822/861b94f9/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proc_ptr_comp_19.f90
Type: application/octet-stream
Size: 520 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090822/861b94f9/attachment-0002.obj>

More information about the Gcc-patches mailing list