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

--- Comment #11 from Steve Kargl <kargl at gcc dot gnu.org> ---
(In reply to anlauf from comment #9)
> (In reply to Steve Kargl from comment #5)
> > (In reply to anlauf from comment #4)
> > > 
> > > I am still struggling with F2023 8.5.7 CONTIGUOUS attribute, which has:
> > > 
> > > An object is contiguous if it is
> > > ...
> > > (7) a nonzero‑sized array section (9.5.3) provided that
> > > ...
> > >    (f) only its final part‑ref has nonzero rank, and
> > > ...
> > > 
> > > Isn't this violated by the testcase in comment#0?
> > 
> > I think that (7) does not apply here.
> > 
> > c => a%x   ! False error?
> > 
> > 'a' is a whole array.  Wouldn't (7) apply to something
> > like 'c => a(2:3)%x'
> 
> So what is the difference between a(:)%x and a(2:3)%x ?

There isn't a difference.  a(:) and a(2:3) are both 
array sections.  The former happens to be equivalent
to the whole array.  One reason I see a(:) used in
code is either block automatic re-allocation on of
a LHS entity or to ensure/indicate conformance.

a(:) = .....       ! block reallocation.
c(2:5) = a(:) .... ! a is a 4-element array.

> FWIW, Intel says:
> 
> pr123782.f90(19): error #8377: An array is not contiguous if any part other
> than final has non-zero rank.   [X]
> c => a%x   ! False error?
> -------^

Well, this looks like Intel is applying (7), which I think is wrong.

> pr123782.f90(19): error #8371: If pointer is declared CONTIGUOUS, target
> must be contiguous as well.   [X]
> c => a%x   ! False error?
> -------^

This may or may not be correct.  As Ivan mentions, the layout of
a derived type may have some padding (for some reason).  The 
memory layout may be 'a(1)%xAAAAa(2)%xAAAA...' where one is
aligning a 4-byte real to 8-byte memory strides.

I do note Fortran standard does not consider implementation
details.  The strided case above I definition 3.37 applies.
a(1)%x and a(2)%x are contiguous.

> 
> Does someone want to ask the Intel people for their opinion?
>

I don't use the Intel compiler, and so, I don't have an account
of the Intel Fortran forum.

> > It seems we have
> > 
> >   An object is contiguous if it is
> >   ...
> >   (2) a nonpointer whole array that is not assumed-shape,
> 
> I found:
> 
> 9.5.2 Whole arrays
> 
> A whole array is a named array or a structure component whose final part‑ref
> is an array component name; no subscript list is appended.
> 
> Now 'x' is not an array component name, or is it, or do I miss something?
>

'a' is the whole array.  Even though 'x' is scalar, Fortran does not 
treat 'a%x' as a scalar.  For the second part of 9.5.2, 

type b
  real x(4)
end type

b%x is a whole array.  b%x(:) is an array section.  b%x(1) is an element.

At least, that's the way I interpret the text.  I guess it's time to
re-read parts of section 9 as I could be missing something.

> > I suppose one can argument that 'a%x' may not be a whole array;
> > in particular, if we have
> > 
> > type :: t1
> >   real :: x
> >   integer :: i
> > end type
> > 
> > then 3.38 seems to apply.
> > 
> > 
> > 3.37
> > contiguous
> > <array> whose array elements, in order, are not separated by other data
> > objects
> > 
> > 3.38
> > contiguous
> > <multi-part data object> whose parts, in order, are not
> > separated by other data objects

Reply via email to