https://gcc.gnu.org/g:122212d2fd6bc9547bb5280ae2f0bef20990f749

commit r17-6069-g122212d2fd6bc9547bb5280ae2f0bef20990f749
Author: Jerry DeLisle <[email protected]>
Date:   Sun Nov 8 18:46:13 2026 -0800

    fortran: Make coarray accessor dummy arguments variables
    
    The dummy arguments of the generated coarray accessor routines were
    given flavor FL_PARAMETER, which marks a named constant.  Give them
    flavor FL_VARIABLE.  The __add_data dummy is a scalar coarray, and as a
    variable it went through gfc_build_qualified_array, which gave it an
    unused static token, as it already did for every descriptorless coarray
    dummy, although the dummy has its token as a hidden argument.  Do not
    create that token when the decl already has one.  Make the patterns in
    coarray_stat_function.f90 accept any token and decl number.
    
    Assisted-by: Claude Opus 5.5
    
    gcc/fortran/ChangeLog:
    
            * coarray.cc (split_expr_at_caf_ref): Give the base dummy
            argument flavor FL_VARIABLE, not FL_PARAMETER.
            (create_get_callback): Likewise for the dummy arguments made by
            ADD_ARG.
            (create_allocated_callback): Likewise.
            (create_send_callback): Likewise.
            * trans-decl.cc (gfc_build_qualified_array): Do not create a
            static token for a decl that already has GFC_DECL_TOKEN.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/coarray_stat_function.f90: Match any caf_token and
            decl number.

Diff:
---
 gcc/fortran/coarray.cc                              | 8 ++++----
 gcc/fortran/trans-decl.cc                           | 4 +++-
 gcc/testsuite/gfortran.dg/coarray_stat_function.f90 | 6 +++---
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index dbca4a152de9..828e73bb4d0c 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -376,7 +376,7 @@ split_expr_at_caf_ref (gfc_expr *expr, gfc_namespace *ns,
   created = !gfc_get_sym_tree (!caf_ref ? expr->symtree->name : "base", ns, 
&st,
                               false);
   gcc_assert (created);
-  st->n.sym->attr.flavor = FL_PARAMETER;
+  st->n.sym->attr.flavor = FL_VARIABLE;
   st->n.sym->attr.dummy = 1;
   st->n.sym->attr.intent = INTENT_IN;
   st->n.sym->ts = *caf_ts;
@@ -857,7 +857,7 @@ create_get_callback (gfc_expr *expr)
   gfc_get_symbol (name, sub_ns, &nsym);                                        
\
   nsym->ts.type = stype;                                                       
\
   nsym->ts.kind = skind;                                                       
\
-  nsym->attr.flavor = FL_PARAMETER;                                            
\
+  nsym->attr.flavor = FL_VARIABLE;                                             
\
   nsym->attr.dummy = 1;                                                        
\
   nsym->attr.intent = sintent;                                                 
\
   nsym->declared_at = expr->where;                                             
\
@@ -1106,7 +1106,7 @@ create_allocated_callback (gfc_expr *expr)
   gfc_get_symbol (name, sub_ns, &nsym);                                        
\
   nsym->ts.type = stype;                                                       
\
   nsym->ts.kind = skind;                                                       
\
-  nsym->attr.flavor = FL_PARAMETER;                                            
\
+  nsym->attr.flavor = FL_VARIABLE;                                             
\
   nsym->attr.dummy = 1;                                                        
\
   nsym->attr.intent = sintent;                                                 
\
   nsym->declared_at = expr->where;                                             
\
@@ -1252,7 +1252,7 @@ create_send_callback (gfc_expr *expr, gfc_expr *rhs)
   gfc_get_symbol (name, sub_ns, &nsym);                                        
\
   nsym->ts.type = stype;                                                       
\
   nsym->ts.kind = skind;                                                       
\
-  nsym->attr.flavor = FL_PARAMETER;                                            
\
+  nsym->attr.flavor = FL_VARIABLE;                                             
\
   nsym->attr.dummy = 1;                                                        
\
   nsym->attr.intent = sintent;                                                 
\
   nsym->declared_at = expr->where;                                             
\
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index f015e26fd2ca..0de93be78297 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1070,9 +1070,11 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   nest = (procns->proc_name->backend_decl != current_function_decl)
         && !sym->attr.contained;
 
+  /* A dummy coarray already has its hidden token argument.  */
   if (array_attr->codimension && flag_coarray == GFC_FCOARRAY_LIB
       && as->type != AS_ASSUMED_SHAPE
-      && GFC_TYPE_ARRAY_CAF_TOKEN (type) == NULL_TREE)
+      && GFC_TYPE_ARRAY_CAF_TOKEN (type) == NULL_TREE
+      && !(DECL_LANG_SPECIFIC (decl) && GFC_DECL_TOKEN (decl)))
     {
       tree token;
       tree token_type = build_qualified_type (pvoid_type_node,
diff --git a/gcc/testsuite/gfortran.dg/coarray_stat_function.f90 
b/gcc/testsuite/gfortran.dg/coarray_stat_function.f90
index 627b07441777..ff2505479c42 100644
--- a/gcc/testsuite/gfortran.dg/coarray_stat_function.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_stat_function.f90
@@ -40,6 +40,6 @@ contains
   
 end program function_stat
 
-! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token.., 0B, 0B, 4, 4, \\\(void \\\*\\\) &D....., 0B, 0B, 0, 
__caf_get_from_remote_fn_index_., 0B, 0, &stat, 0B, 0B\\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token.., 0B, 0B, 1, 4, \\\(void \\\*\\\) &D....., 0B, 0B, 0, 
__caf_get_from_remote_fn_index_., 0B, 0, &stat2, 0B, 0B\\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token.., 0B, 0B, 3, 4, \\\(void \\\*\\\) &D....., 0B, 0B, 0, 
__caf_get_from_remote_fn_index_., 0B, 0, &stat, 0B, 0B\\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token\\.\[0-9\]+, 0B, 0B, 4, 4, \\\(void \\\*\\\) &D\\.\[0-9\]+, 0B, 
0B, 0, __caf_get_from_remote_fn_index_., 0B, 0, &stat, 0B, 0B\\\);" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token\\.\[0-9\]+, 0B, 0B, 1, 4, \\\(void \\\*\\\) &D\\.\[0-9\]+, 0B, 
0B, 0, __caf_get_from_remote_fn_index_., 0B, 0, &stat2, 0B, 0B\\\);" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_get_from_remote 
\\\(caf_token\\.\[0-9\]+, 0B, 0B, 3, 4, \\\(void \\\*\\\) &D\\.\[0-9\]+, 0B, 
0B, 0, __caf_get_from_remote_fn_index_., 0B, 0, &stat, 0B, 0B\\\);" 1 
"original" } }

Reply via email to