Fortran: Fix fndecl with -fcoarray=lib [PR99817]
authorTobias Burnus <tobias@codesourcery.com>
Fri, 9 Apr 2021 08:18:24 +0000 (10:18 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 9 Apr 2021 08:41:39 +0000 (10:41 +0200)
gcc/fortran/ChangeLog:

PR fortran/99817
* trans-types.c (gfc_get_function_type): Also generate hidden
coarray argument for character arguments.

gcc/testsuite/ChangeLog:

PR fortran/99817
* gfortran.dg/coarray/dummy_2.f90: New test.

gcc/fortran/trans-types.c
gcc/testsuite/gfortran.dg/coarray/dummy_2.f90 [new file with mode: 0644]

index bc7aac1..9f21b3e 100644 (file)
@@ -3152,14 +3152,14 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
        vec_safe_push (typelist, boolean_type_node);
       /* Coarrays which are descriptorless or assumed-shape pass with
         -fcoarray=lib the token and the offset as hidden arguments.  */
-      else if (arg
-              && flag_coarray == GFC_FCOARRAY_LIB
-              && ((arg->ts.type != BT_CLASS
-                   && arg->attr.codimension
-                   && !arg->attr.allocatable)
-                  || (arg->ts.type == BT_CLASS
-                      && CLASS_DATA (arg)->attr.codimension
-                      && !CLASS_DATA (arg)->attr.allocatable)))
+      if (arg
+         && flag_coarray == GFC_FCOARRAY_LIB
+         && ((arg->ts.type != BT_CLASS
+              && arg->attr.codimension
+              && !arg->attr.allocatable)
+             || (arg->ts.type == BT_CLASS
+                 && CLASS_DATA (arg)->attr.codimension
+                 && !CLASS_DATA (arg)->attr.allocatable)))
        {
          vec_safe_push (typelist, pvoid_type_node);  /* caf_token.  */
          vec_safe_push (typelist, gfc_array_index_type);  /* caf_offset.  */
diff --git a/gcc/testsuite/gfortran.dg/coarray/dummy_2.f90 b/gcc/testsuite/gfortran.dg/coarray/dummy_2.f90
new file mode 100644 (file)
index 0000000..3526374
--- /dev/null
@@ -0,0 +1,26 @@
+! { dg-do compile }
+!
+! PR fortran/99817
+!
+! Contributed by G. Steinmetz
+!
+subroutine s1 (x)
+   character(*) :: x(*)[*]
+end
+
+subroutine s2 (x)
+   character(*), dimension(*), codimension[*] :: x
+   integer :: i
+   i = len(x)
+end
+
+subroutine s3 (x, y)
+   character(*), dimension(:) :: x[*]
+   character(*) :: y
+end
+
+subroutine s4 (x, y, z)
+   character(*), dimension(:) :: x[2, *]
+   character(*), dimension(*) :: y
+   character(*) :: z
+end