https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122977

--- Comment #8 from anlauf at gcc dot gnu.org ---
(In reply to Steve Kargl from comment #7)
> This seems to allow your testcase to pass.  I haven't regression
> tested yet.
> 
> 
> diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
> index b25cd2c2388..65e135b9908 100644
> --- a/gcc/fortran/simplify.cc
> +++ b/gcc/fortran/simplify.cc
> @@ -7362,6 +7362,13 @@ do_xor (gfc_expr *result, gfc_expr *e)
>  gfc_expr *
>  gfc_simplify_is_contiguous (gfc_expr *array)
>  {
> +  if (array->expr_type == EXPR_VARIABLE
> +      && array->symtree->n.sym->attr.associate_var == 1
> +      && array->symtree->n.sym->attr.dimension > 0
> +      && array->symtree->n.sym->assoc
> +      && array->symtree->n.sym->assoc->target)
> +    return gfc_simplify_is_contiguous
> (array->symtree->n.sym->assoc->target);
> +
>    if (gfc_is_simply_contiguous (array, false, true))
>      return gfc_get_logical_expr (gfc_default_logical_kind, &array->where,
> 1);

Yeah, this goes into the right direction.

I also thought about nested associate constructs and arrived at this patch
instead of the one in comment#2:

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 00abd9e8734..2549726ba4c 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -6406,6 +6455,14 @@ gfc_is_simply_contiguous (gfc_expr *expr, bool strict,
bool permit_element)
              || (sym->as && sym->as->type == AS_ASSUMED_SHAPE))))
     return false;

+  /* An associate variable may point to a non-contiguous target.  */
+  if (ar && ar->type == AR_FULL
+      && sym->attr.associate_var && !sym->attr.contiguous
+      && sym->assoc
+      && sym->assoc->target)
+    return gfc_is_simply_contiguous (sym->assoc->target, strict,
+                                    permit_element);
+
   if (!ar || ar->type == AR_FULL)
     return true;

Needs testing.

Reply via email to