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

            Bug ID: 127701
           Summary: Contiguous parts of non-contiguous associate names are
                    not recognized as contiguous
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikael at gcc dot gnu.org
  Target Milestone: ---

Consider this example:

program prog
   implicit none
   integer, parameter :: n = 3
   type :: t1
      integer :: c1(n,n)
   end type
   type(t1), target :: x(n)
   integer :: i, j
   x = (/ (t1(reshape([ (i+j, j=1,n*n) ], [n,n])), i=1,n) /)
   call sub(x)
contains
   subroutine sub(y)
      type(t1), target :: y(:)
      integer, contiguous, pointer :: p(:)
      associate(z => y)
         p(1:n*n) => z(1)%c1
      end associate
   end subroutine
end program

It is rejected with the error:
> 
>    16 |          p(1:n*n) => z(1)%c1
>       |                     1
> Error: Rank remapping target must be rank 1 or simply contiguous at (1)
even if the target is clearly simply contiguous.

This is caused by the following code in the implementation of
gfc_is_simply_contiguous, that forwards the check from the associate symbol to
the associate target, without checking whether there are any subreferences to
the associate symbol:

  6492    /* An associate variable may point to a non-contiguous target.  */
  6493    if (ar && ar->type == AR_FULL
  6494        && sym->attr.associate_var && !sym->attr.contiguous
  6495        && sym->assoc
  6496        && sym->assoc->target)
  6497      return gfc_is_simply_contiguous (sym->assoc->target, strict,
  6498                                       permit_element);

Reply via email to