[Fortran] diagnostic for argument w/type parameters for assumed-type dummy

Message ID 8bc80383-d339-eff3-36e5-3250c73745e9@codesourcery.com
State New
Headers
Series [Fortran] diagnostic for argument w/type parameters for assumed-type dummy |

Commit Message

Sandra Loosemore Sept. 22, 2021, 2:58 p.m. UTC
  This patch is adds the missing diagnostic noted in PR fortran/101319. 
OK to commit?

-Sandra
  

Comments

Tobias Burnus Sept. 22, 2021, 3:27 p.m. UTC | #1
On 22.09.21 16:58, Sandra Loosemore wrote:

> This patch is adds the missing diagnostic noted in PR fortran/101319.
> OK to commit?

LGTM. Thanks!

For reference, the F2018 wording is: "If the actual argument is of a
derived type that has type parameters, type-bound procedures, or final
subroutines, the dummy argument shall not be assumed-type."

Tobias

> commit 9d5b9062d728d1b1bf5acfb914e06d776bdcdb60
> Author: Sandra Loosemore<sandra@codesourcery.com>
> Date:   Wed Sep 22 07:49:17 2021 -0700
>
>      Fortran: diagnostic for argument w/type parameters for assumed-type dummy
>
>      2021-09-22  Sandra Loosemore<sandra@codesourcery.com>
>
>       PR fortran/101319
>
>      gcc/fortran/
>       * interface.c (gfc_compare_actual_formal): Extend existing
>       assumed-type diagnostic to also check for argument with type
>       parameters.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

commit 9d5b9062d728d1b1bf5acfb914e06d776bdcdb60
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Wed Sep 22 07:49:17 2021 -0700

    Fortran: diagnostic for argument w/type parameters for assumed-type dummy
    
    2021-09-22  Sandra Loosemore  <sandra@codesourcery.com>
    
    	PR fortran/101319
    
    gcc/fortran/
    	* interface.c (gfc_compare_actual_formal): Extend existing
    	assumed-type diagnostic to also check for argument with type
    	parameters.
    
    gcc/testsuite/
    	* gfortran.dg/c-interop/assumed-type-dummy.f90: Remove xfail.

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index f9a7c9c..dae4b95 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3183,21 +3183,21 @@  gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
 			      is_elemental, where))
 	return false;
 
-      /* TS 29113, 6.3p2.  */
+      /* TS 29113, 6.3p2; F2018 15.5.2.4.  */
       if (f->sym->ts.type == BT_ASSUMED
 	  && (a->expr->ts.type == BT_DERIVED
 	      || (a->expr->ts.type == BT_CLASS && CLASS_DATA (a->expr))))
 	{
-	  gfc_namespace *f2k_derived;
-
-	  f2k_derived = a->expr->ts.type == BT_DERIVED
-			? a->expr->ts.u.derived->f2k_derived
-			: CLASS_DATA (a->expr)->ts.u.derived->f2k_derived;
-
-	  if (f2k_derived
-	      && (f2k_derived->finalizers || f2k_derived->tb_sym_root))
+	  gfc_symbol *derived = (a->expr->ts.type == BT_DERIVED
+				 ? a->expr->ts.u.derived
+				 : CLASS_DATA (a->expr)->ts.u.derived);
+	  gfc_namespace *f2k_derived = derived->f2k_derived;
+	  if (derived->attr.pdt_type
+	      || (f2k_derived
+		  && (f2k_derived->finalizers || f2k_derived->tb_sym_root)))
 	    {
-	      gfc_error ("Actual argument at %L to assumed-type dummy is of "
+	      gfc_error ("Actual argument at %L to assumed-type dummy "
+			 "has type parameters or is of "
 			 "derived type with type-bound or FINAL procedures",
 			 &a->expr->where);
 	      return false;
diff --git a/gcc/testsuite/gfortran.dg/c-interop/assumed-type-dummy.f90 b/gcc/testsuite/gfortran.dg/c-interop/assumed-type-dummy.f90
index a14c9a5..24bdf2b 100644
--- a/gcc/testsuite/gfortran.dg/c-interop/assumed-type-dummy.f90
+++ b/gcc/testsuite/gfortran.dg/c-interop/assumed-type-dummy.f90
@@ -73,7 +73,7 @@  contains
     type(t4) :: a4
 
     call s1 (a1)  ! OK
-    call s1 (a2)  ! { dg-error "assumed-type dummy" "pr101319" { xfail *-*-* } }
+    call s1 (a2)  ! { dg-error "assumed-type dummy" }
     call s1 (a3)  ! { dg-error "assumed-type dummy" }
     call s1 (a4)  ! { dg-error "assumed-type dummy" }
   end subroutine