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

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to Steve Kargl from comment #3)
> (In reply to anlauf from comment #1)
> > Mine.
> > 
> > Untested fix:
> > 
> > diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
> > index 9f3ce1d2ad6..66929f714cc 100644
> > --- a/gcc/fortran/resolve.cc
> > +++ b/gcc/fortran/resolve.cc
> > @@ -18143,6 +18217,7 @@ skip_interfaces:
> >  
> >    /* F2008, C530.  */
> >    if (sym->attr.contiguous
> > +      && !sym->attr.associate_var
> >        && (!class_attr.dimension
> >       || (as->type != AS_ASSUMED_SHAPE && as->type != AS_ASSUMED_RANK
> >           && !class_attr.pointer)))
> 
> I've tested this patch on amd64-*-freebsd.  It fixes the OP's problem,
> and regression tests pass.  OK to commit as obvious.
> 
> I haven't looked at the issue with gfc_is_simply_contiguous() in
> comment #2, but if it passes regression testing, and you have a
> testcase (or two) feel free to commit.  The comment in the patch
> explains the rationale.

The change in comment#2 regresses on gfortran.dg/associate_11.f90
because it will pack the associate variable before passing to a subroutine.
I don't have a simple answer yet.

The reason for the latter change is this extended testcase:


! { dg-do run }
! { dg-options "-fdump-tree-original" }
!
! PR fortran/122977

program foo
  integer, dimension(:), pointer, contiguous :: a
  allocate (a(4))
  if (.not. is_contiguous(a)) error stop 1    ! shall get optimized out
  associate (b => a)
    if (.not. is_contiguous(b)) error stop 2  ! shall get optimized out
  end associate
  associate (c => a(1::2))
    if (is_contiguous(c)) stop 3              ! runtime check
  end associate
end program foo

! { dg-final { scan-tree-dump "_gfortran_stop_numeric \\(3, 0\\)" "original" }
}
! { dg-final { scan-tree-dump-not "_gfortran_error_stop_numeric" "original" } }


Before, gfc_is_simply_contiguous would see the AR_FULL for c and think
it were contiguous.

Reply via email to