]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix func decl mismatch [PR93660]
authorTobias Burnus <tobias@codesourcery.com>
Tue, 23 Mar 2021 14:45:36 +0000 (15:45 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 23 Mar 2021 14:45:36 +0000 (15:45 +0100)
gcc/fortran/ChangeLog:

PR fortran/93660
* trans-decl.c (build_function_decl): Add comment;
increment hidden_typelist for caf_token/caf_offset.
* trans-types.c (gfc_get_function_type): Add comment;
add missing caf_token/caf_offset args.

gcc/testsuite/ChangeLog:

PR fortran/93660
* gfortran.dg/gomp/declare-simd-coarray-lib.f90: New test.

gcc/fortran/trans-decl.c
gcc/fortran/trans-types.c
gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90 [new file with mode: 0644]

index 6a4ed9bbfdd5fa006de9f7f4d55f36efc03e4be2..34a0d49bae7e2629c2079b2d2d6584052d76d869 100644 (file)
@@ -2488,7 +2488,9 @@ build_function_decl (gfc_symbol * sym, bool global)
 }
 
 
-/* Create the DECL_ARGUMENTS for a procedure.  */
+/* Create the DECL_ARGUMENTS for a procedure.
+   NOTE: The arguments added here must match the argument type created by
+   gfc_get_function_type ().  */
 
 static void
 create_function_arglist (gfc_symbol * sym)
@@ -2807,6 +2809,7 @@ create_function_arglist (gfc_symbol * sym)
          DECL_ARG_TYPE (token) = TREE_VALUE (typelist);
          TREE_READONLY (token) = 1;
          hidden_arglist = chainon (hidden_arglist, token);
+         hidden_typelist = TREE_CHAIN (hidden_typelist);
          gfc_finish_decl (token);
 
          offset = build_decl (input_location, PARM_DECL,
@@ -2832,6 +2835,7 @@ create_function_arglist (gfc_symbol * sym)
          DECL_ARG_TYPE (offset) = TREE_VALUE (typelist);
          TREE_READONLY (offset) = 1;
          hidden_arglist = chainon (hidden_arglist, offset);
+         hidden_typelist = TREE_CHAIN (hidden_typelist);
          gfc_finish_decl (offset);
        }
 
index ccdc4687c3931b10554ddd210238a920b41a3115..bc7aac1f3d912cf35480a05ed78f74f519ab2ec2 100644 (file)
@@ -3011,6 +3011,10 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
   return build_type_attribute_variant (fntype, tmp);
 }
 
+
+/* NOTE: The returned function type must match the argument list created by
+   create_function_arglist.  */
+
 tree
 gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
                       const char *fnspec)
@@ -3119,10 +3123,11 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
         }
     }
 
-  /* Add hidden string length parameters.  */
+  /* Add hidden arguments.  */
   for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
     {
       arg = f->sym;
+      /* Add hidden string length parameters.  */
       if (arg && arg->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
        {
          if (!arg->ts.deferred)
@@ -3145,6 +3150,20 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
               && arg->ts.type != BT_CLASS
               && !gfc_bt_struct (arg->ts.type))
        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)))
+       {
+         vec_safe_push (typelist, pvoid_type_node);  /* caf_token.  */
+         vec_safe_push (typelist, gfc_array_index_type);  /* caf_offset.  */
+       }
     }
 
   if (!vec_safe_is_empty (typelist)
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90
new file mode 100644 (file)
index 0000000..1f74da7
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-additional-options "-fcoarray=lib" }
+!
+! PR fortran/93660
+!
+! Failed as TREE_TYPE(fndecl) did not include the
+! hidden caf_token/caf_offset arguments.
+!
+integer function f(x)
+   integer :: x[*]
+   !$omp declare simd
+   f = x[1]
+end