https://gcc.gnu.org/g:c0d877bc00edfd11cd0332c72cf0650e4ad8f948

commit c0d877bc00edfd11cd0332c72cf0650e4ad8f948
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sun Aug 10 22:54:42 2025 +0200

    Correction PR100094

Diff:
---
 gcc/fortran/trans-array.cc      | 6 ++++--
 gcc/fortran/trans-descriptor.cc | 9 +++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e6553e5d74f5..3e32210c8f6c 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11855,10 +11855,12 @@ gfc_trans_deferred_array (gfc_symbol * sym, 
gfc_wrapped_block * block)
 
   /* NULLIFY the data pointer for non-saved allocatables, or for non-saved
      pointers when -fcheck=pointer is specified.  */
-  if (GFC_DESCRIPTOR_TYPE_P (type) && !sym->attr.save
+  if (GFC_DESCRIPTOR_TYPE_P (type)
       && (sym->attr.allocatable || sym->attr.pointer))
     {
-      if (flag_coarray == GFC_FCOARRAY_LIB && sym->attr.codimension)
+      if (flag_coarray == GFC_FCOARRAY_LIB
+         && sym->attr.codimension
+         && !sym->attr.save)
        {
          /* Declare the variable static so its array descriptor stays present
             after leaving the scope.  It may still be accessed through another
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 799a8e69c000..12adb1115175 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -945,13 +945,18 @@ gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, tree descr)
 {
   /* NULLIFY the data pointer for non-saved allocatables, or for non-saved
      pointers when -fcheck=pointer is specified.  */
-  if (sym->attr.allocatable
-      || (sym->attr.pointer && (gfc_option.rtcheck & GFC_RTCHECK_POINTER)))
+  if (!sym->attr.save
+      && (sym->attr.allocatable
+         || (sym->attr.pointer
+             && (gfc_option.rtcheck & GFC_RTCHECK_POINTER))))
     {
       gfc_conv_descriptor_data_set (block, descr, null_pointer_node);
       if (flag_coarray == GFC_FCOARRAY_LIB && sym->attr.codimension)
        gfc_conv_descriptor_token_set (block, descr, null_pointer_node);
+    }
 
+  if (sym->attr.allocatable || sym->attr.pointer)
+    {
       gcc_assert (sym->as && sym->as->rank>=0);
       tree etype = gfc_get_element_type (TREE_TYPE (descr));
       gfc_conv_descriptor_dtype_set (block, descr,

Reply via email to