Debian Codegraph @

gcc/testsuite/gfortran.dg/contiguous_11.f90

raw
1 ! { dg-do compile }
2 !
3 ! PR fortran/97242
4 !
5 implicit none
6 type t
7 integer, allocatable :: A(:,:,:)
8 integer :: D(5,5,5)
9 end type t
10
11 type(t), target :: B(5)
12 integer, pointer, contiguous :: P(:,:,:)
13 integer, target :: C(5,5,5)
14 integer :: i
15
16 i = 1
17
18 ! OK: contiguous
19 P => B(i)%A
20 P => B(i)%A(:,:,:)
21 P => C
22 P => C(:,:,:)
23 call foo (B(i)%A)
24 call foo (B(i)%A(:,:,:))
25 call foo (C)
26 call foo (C(:,:,:))
27
28 ! Invalid - not contiguous
29 ! "If the pointer object has the CONTIGUOUS attribute, the pointer target shall be contiguous."
30 ! → known to be noncontigous (not always checkable, however)
31 P => B(i)%A(:,::3,::4) ! <<< Unknown as (1:2:3,1:3:4) is contiguous and has one element.
32 P => B(i)%D(:,::2,::2) ! { dg-error "Assignment to contiguous pointer from non-contiguous target" }
33 P => C(::2,::2,::2) ! { dg-error "Assignment to contiguous pointer from non-contiguous target" }
34
35 ! This following is stricter:
36 ! C1541 The actual argument corresponding to a dummy pointer with the
37 ! CONTIGUOUS attribute shall be simply contiguous (9.5.4).
38 call foo (B(i)%A(:,::3,::4)) ! { dg-error "must be simply contiguous" }
39 call foo (C(::2,::2,::2)) ! { dg-error "must be simply contiguous" }
40
41 contains
42 subroutine foo(Q)
43 integer, pointer, intent(in), contiguous :: Q(:,:,:)
44 end subroutine foo
45 end