https://gcc.gnu.org/g:84947575bd0281cd4d99f1a31029ca4da11fc997

commit r16-1697-g84947575bd0281cd4d99f1a31029ca4da11fc997
Author: Andre Vehreschild <ve...@gcc.gnu.org>
Date:   Wed Jun 25 12:27:04 2025 +0200

    Fortran: Fix wasting memory in coarray single mode.
    
    gcc/fortran/ChangeLog:
    
            * resolve.cc (resolve_fl_derived0): Do not create the token
            component when not in coarray lib mode.
            * trans-types.cc: Do not access the token when not in coarray
            lib mode.

Diff:
---
 gcc/fortran/resolve.cc     | 4 ++--
 gcc/fortran/trans-types.cc | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 7089e4f171d1..58f7aee29c35 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -16841,8 +16841,8 @@ resolve_fl_derived0 (gfc_symbol *sym)
     return false;
 
   /* Now add the caf token field, where needed.  */
-  if (flag_coarray != GFC_FCOARRAY_NONE
-      && !sym->attr.is_class && !sym->attr.vtype)
+  if (flag_coarray == GFC_FCOARRAY_LIB && !sym->attr.is_class
+      && !sym->attr.vtype)
     {
       for (c = sym->components; c; c = c->next)
        if (!c->attr.dimension && !c->attr.codimension
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index e15b1bb89f01..1754d9821532 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3187,7 +3187,7 @@ copy_derived_types:
     for (c = derived->components; c; c = c->next)
       {
        /* Do not add a caf_token field for class container components.  */
-       if ((codimen || coarray_flag) && !c->attr.dimension
+       if (codimen && coarray_flag && !c->attr.dimension
            && !c->attr.codimension && (c->attr.allocatable || c->attr.pointer)
            && !derived->attr.is_class)
          {

Reply via email to