https://gcc.gnu.org/g:51323eb87cde1f6652a42d5db0f2e848d56094e9

commit 51323eb87cde1f6652a42d5db0f2e848d56094e9
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri Jan 24 21:15:38 2025 +0100

    Correction régression bind-c-contiguous-1.f90

Diff:
---
 gcc/fortran/trans-decl.cc | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 1a9eb3f00d17..baa36e88bf15 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7212,16 +7212,6 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   else
     rank = build_int_cst (signed_char_type_node, sym->as->rank);
 
-  if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc)))
-    {
-      tree offset, type;
-      type = TREE_TYPE (gfc_desc);
-      gfc_trans_array_bounds (type, sym, &offset, &block);
-      if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
-       gfc_add_modify (&block, GFC_TYPE_ARRAY_OFFSET (type), offset);
-      goto done;
-    }
-
   stmtblock_t block2;
   gfc_init_block (&block2);
 
@@ -7230,8 +7220,9 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
        && (sym->as->type == AS_ASSUMED_SIZE || sym->as->type == AS_EXPLICIT))
       || sym->attr.contiguous;
 
-  gfc_set_gfc_from_cfi (&block, &block2, gfc_desc, cfi, rank, sym,
-                       true, do_copy_inout, false);
+  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc)))
+    gfc_set_gfc_from_cfi (&block, &block2, gfc_desc, cfi, rank, sym,
+                         true, do_copy_inout, false);
 
   /* With bind(C), the standard requires that both Fortran callers and callees
      handle noncontiguous arrays passed to an dummy with 'contiguous' attribute
@@ -7389,6 +7380,16 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
       gfc_add_expr_to_block (&block, tmp);
     }
 
+  if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc)))
+    {
+      tree offset, type;
+      type = TREE_TYPE (gfc_desc);
+      gfc_trans_array_bounds (type, sym, &offset, &block);
+      if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
+       gfc_add_modify (&block, GFC_TYPE_ARRAY_OFFSET (type), offset);
+      goto done;
+    }
+
   if (sym->attr.allocatable || sym->attr.pointer)
     {
       tmp = gfc_get_cfi_desc_base_addr (cfi),

Reply via email to