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

commit d3f52d26598b25ed9957cceb8445a59b4bc7e740
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri May 30 22:16:46 2025 +0200

    Correction régression deferred_type_component_3

Diff:
---
 gcc/fortran/trans.cc | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 2a32b6f0c7bb..55bf78a7d962 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1882,8 +1882,12 @@ gfc_deallocate_with_status (tree pointer, tree status, 
tree errmsg, tree errlen,
                            omp_tmp, tmp);
        }
       gfc_add_expr_to_block (&non_null, tmp);
-      gfc_add_modify (&non_null, pointer, build_int_cst (TREE_TYPE (pointer),
-                                                        0));
+      if (descr)
+       gfc_conv_descriptor_data_set (&non_null, descr,
+                                     build_int_cst (ptr_type_node, 0));
+      else
+       gfc_add_modify (&non_null, pointer,
+                       build_int_cst (TREE_TYPE (pointer), 0));
       if (flag_openmp_allocators && descr)
        gfc_conv_descriptor_version_set (&non_null, descr, integer_zero_node);
 
@@ -1949,10 +1953,19 @@ gfc_deallocate_with_status (tree pointer, tree status, 
tree errmsg, tree errlen,
       if (status != NULL_TREE && !integer_zerop (status))
        {
          tree stat = build_fold_indirect_ref_loc (input_location, status);
-         tree nullify = fold_build2_loc (input_location, MODIFY_EXPR,
-                                         void_type_node, pointer,
-                                         build_int_cst (TREE_TYPE (pointer),
-                                                        0));
+         tree nullify;
+         if (descr)
+           {
+             stmtblock_t blk;
+             gfc_init_block (&blk);
+             gfc_conv_descriptor_data_set (&blk, descr,
+                                           build_int_cst (ptr_type_node, 0));
+             nullify = gfc_finish_block (&blk);
+           }
+         else
+           nullify = fold_build2_loc (input_location, MODIFY_EXPR,
+                                      void_type_node, pointer,
+                                      build_int_cst (TREE_TYPE (pointer), 0));
 
          TREE_USED (label_finish) = 1;
          tmp = build1_v (GOTO_EXPR, label_finish);
@@ -1963,6 +1976,9 @@ gfc_deallocate_with_status (tree pointer, tree status, 
tree errmsg, tree errlen,
                                 tmp, nullify);
          gfc_add_expr_to_block (&non_null, tmp);
        }
+      else if (descr)
+       gfc_conv_descriptor_data_set (&non_null, descr,
+                                     build_int_cst (ptr_type_node, 0));
       else
        gfc_add_modify (&non_null, pointer, build_int_cst (TREE_TYPE (pointer),
                                                           0));

Reply via email to