diff mbox

[Fortran] PR 60507: Passing function call into procedure argument not caught

Message ID CAKwh3qhP7KPMbORNABj8X0Zjpr1TQsL990EGpC35ei=FHEjrhg@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Dec. 29, 2014, 12:50 p.m. UTC
Hi all,

here is a patch to improve diagnostics for dummy procedures. Regtested
on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus



2014-12-29  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/60507
    * interface.c (is_procptr_result): New function to check if an
    expression is a procedure-pointer result.
    (compare_actual_formal): Use it.

2014-12-29  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/60507
    * gfortran.dg/dummy_procedure_11: New.

Comments

Janus Weil Dec. 31, 2014, 5:41 p.m. UTC | #1
(early) ping!


2014-12-29 13:50 GMT+01:00 Janus Weil <janus@gcc.gnu.org>:
> Hi all,
>
> here is a patch to improve diagnostics for dummy procedures. Regtested
> on x86_64-unknown-linux-gnu. Ok for trunk?
>
> Cheers,
> Janus
>
>
>
> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>
>     PR fortran/60507
>     * interface.c (is_procptr_result): New function to check if an
>     expression is a procedure-pointer result.
>     (compare_actual_formal): Use it.
>
> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>
>     PR fortran/60507
>     * gfortran.dg/dummy_procedure_11: New.
Tobias Burnus Dec. 31, 2014, 6:13 p.m. UTC | #2
Janus Weil wrote:
> here is a patch to improve diagnostics for dummy procedures. Regtested
> on x86_64-unknown-linux-gnu. Ok for trunk?

Looks good to me. Thanks for the patch!

Tobias

> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>
>      PR fortran/60507
>      * interface.c (is_procptr_result): New function to check if an
>      expression is a procedure-pointer result.
>      (compare_actual_formal): Use it.
>
> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>
>      PR fortran/60507
>      * gfortran.dg/dummy_procedure_11: New.
Janus Weil Jan. 2, 2015, 11:28 a.m. UTC | #3
2014-12-31 19:13 GMT+01:00 Tobias Burnus <burnus@net-b.de>:
>> here is a patch to improve diagnostics for dummy procedures. Regtested
>> on x86_64-unknown-linux-gnu. Ok for trunk?
>
> Looks good to me. Thanks for the patch!

Thanks, committed as r219141.

Cheers,
Janus



>> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>>
>>      PR fortran/60507
>>      * interface.c (is_procptr_result): New function to check if an
>>      expression is a procedure-pointer result.
>>      (compare_actual_formal): Use it.
>>
>> 2014-12-29  Janus Weil  <janus@gcc.gnu.org>
>>
>>      PR fortran/60507
>>      * gfortran.dg/dummy_procedure_11: New.
diff mbox

Patch

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(Revision 219098)
+++ gcc/fortran/interface.c	(Arbeitskopie)
@@ -2503,6 +2503,18 @@  gfc_has_vector_subscript (gfc_expr *e)
 }
 
 
+static bool
+is_procptr_result (gfc_expr *expr)
+{
+  gfc_component *c = gfc_get_proc_ptr_comp (expr);
+  if (c)
+    return (c->ts.interface && (c->ts.interface->attr.proc_pointer == 1));
+  else
+    return ((expr->symtree->n.sym->result != expr->symtree->n.sym)
+	    && (expr->symtree->n.sym->result->attr.proc_pointer == 1));
+}
+
+
 /* Given formal and actual argument lists, see if they are compatible.
    If they are compatible, the actual argument list is sorted to
    correspond with the formal list, and elements for missing optional
@@ -2724,10 +2736,10 @@  compare_actual_formal (gfc_actual_arglist **ap, gf
          argument is provided for a procedure pointer formal argument.  */
       if (f->sym->attr.proc_pointer
 	  && !((a->expr->expr_type == EXPR_VARIABLE
-		&& a->expr->symtree->n.sym->attr.proc_pointer)
+		&& (a->expr->symtree->n.sym->attr.proc_pointer
+		    || gfc_is_proc_ptr_comp (a->expr)))
 	       || (a->expr->expr_type == EXPR_FUNCTION
-		   && a->expr->symtree->n.sym->result->attr.proc_pointer)
-	       || gfc_is_proc_ptr_comp (a->expr)))
+		   && is_procptr_result (a->expr))))
 	{
 	  if (where)
 	    gfc_error ("Expected a procedure pointer for argument %qs at %L",
@@ -2738,7 +2750,12 @@  compare_actual_formal (gfc_actual_arglist **ap, gf
       /* Satisfy F03:12.4.1.3 by ensuring that a procedure actual argument is
 	 provided for a procedure formal argument.  */
       if (f->sym->attr.flavor == FL_PROCEDURE
-	  && gfc_expr_attr (a->expr).flavor != FL_PROCEDURE)
+	  && !((a->expr->expr_type == EXPR_VARIABLE
+		&& (a->expr->symtree->n.sym->attr.flavor == FL_PROCEDURE
+		    || a->expr->symtree->n.sym->attr.proc_pointer
+		    || gfc_is_proc_ptr_comp (a->expr)))
+	       || (a->expr->expr_type == EXPR_FUNCTION
+		   && is_procptr_result (a->expr))))
 	{
 	  if (where)
 	    gfc_error ("Expected a procedure for argument %qs at %L",