On 11/8/26 2:07 AM, Mikael Morin wrote:
Le 08/11/2026 à 10:15, Thomas Koenig a écrit :
Hi,

debugging a regression on a patch, I just stumbled across a
symbol with addr.flavor = FL_PARAMETER and attr.dummy = 1, which
IMHO makes less than zero sense.

This apparently comes from, in coarray.cc,

#define ADD_ARG(name, nsym, stype, skind, sintent)                             \
   gfc_get_symbol (name, sub_ns, &nsym);                                        
\
   nsym->ts.type = stype;                                                       
\
   nsym->ts.kind = skind;                                                       
\
   nsym->attr.flavor = FL_PARAMETER;                                            
\
   nsym->attr.dummy = 1;                                                        
\
   nsym->attr.intent = sintent;                                                 
\
   nsym->declared_at = expr-  >where;                                             \
   gfc_set_sym_referenced (nsym);                                               
\
   *argptr = gfc_get_formal_arglist ();                                         
\
   (*argptr)->sym = nsym;                                                       
\

However, I'm not into coarray code, so there may be some hidden meaning
to it after all.

Comments?.
This could have been written by a person knowing less the fortran world than the C or middle-end world, where "parameter" means procedure argument.


Best regards

     Thomas


Nice catch Thomas!

It needs to change to FL_VARIABLE in four places. This wiggles on one test case so it is adjusted.

See attached trivial patch.

I will commit this tomorrow.

Regression tested on x86_64 -m32 and -m64

Cheers,

Jerry

---

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.
---


From 65b6dfe5f563b7178cba3cf0879bccab35cc41fd Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Sun, 8 Nov 2026 18:46:13 -0800
Subject: [PATCH] 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.
---
 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 dbca4a152de..828e73bb4d0 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 f015e26fd2c..0de93be7829 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 627b0744177..ff2505479c4 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" } }
-- 
2.56.0

Reply via email to