Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/shape-poly.f90

raw
1 ! { dg-do run }
2 !
3 ! TS 29113
4 ! 6.4.1 SHAPE
5 !
6 ! The description of the intrinsic function SHAPE in ISO/IEC 1539-1:2010
7 ! is changed for an assumed-rank array that is associated with an
8 ! assumed-size array; an assumed-size array has no shape, but in this
9 ! case the result has a value equal to
10 ! [ (SIZE (ARRAY, I, KIND), I=1,RANK (ARRAY)) ]
11 ! with KIND omitted from SIZE if it was omitted from SHAPE.
12 !
13 ! The idea here is that the main program passes some arrays to a test
14 ! subroutine with an assumed-size dummy, which in turn passes that to a
15 ! subroutine with an assumed-rank dummy.
16 !
17 ! This is the polymorphic version of shape.f90.
18
19 module m
20 type :: t
21 integer :: id
22 real :: xyz(3)
23 end type
24 end module
25
26 program test
27 use m
28
29 ! Define some arrays for testing.
30 type(t), target :: x1(5)
31 type(t) :: y1(0:9)
32 class(t), pointer :: p1(:)
33 class(t), allocatable :: a1(:)
34 type(t), target :: x3(2,3,4)
35 type(t) :: y3(0:1,-3:-1,4)
36 class(t), pointer :: p3(:,:,:)
37 type(t), allocatable :: a3(:,:,:)
38
39 ! Test the 1-dimensional arrays.
40 call test1 (x1)
41 call test1 (y1)
42 p1 => x1
43 call test1 (p1)
44 allocate (a1(5))
45 call test1 (a1)
46
47 ! Test the multi-dimensional arrays.
48 call test3 (x3, 1, 2, 1, 3)
49 call test3 (y3, 0, 1, -3, -1)
50 p3 => x3
51 call test3 (p3, 1, 2, 1, 3)
52 allocate (a3(2,3,4))
53 call test3 (a3, 1, 2, 1, 3)
54
55 contains
56
57 subroutine testit (a)
58 use m
59 class(t) :: a(..)
60
61 integer :: r
62 r = rank(a)
63
64 block
65 integer :: s(r)
66 s = shape(a)
67 do i = 1, r
68 if (s(i) .ne. size(a,i)) stop 101
69 end do
70 end block
71
72 end subroutine
73
74 subroutine test1 (a)
75 use m
76 class(t) :: a(*)
77
78 call testit (a)
79 end subroutine
80
81 subroutine test3 (a, l1, u1, l2, u2)
82 use m
83 integer :: l1, u1, l2, u2
84 class(t) :: a(l1:u1, l2:u2, *)
85
86 call testit (a)
87 end subroutine
88
89 end program