Debian Codegraph @

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

raw
1 ! Reported as pr94070.
2 ! { dg-do run }
3 !
4 ! TS 29113
5 ! 6.4.2 SIZE
6 !
7 ! The description of the intrinsic function SIZE in ISO/IEC 1539-1:2010
8 ! is changed in the following cases:
9 !
10 ! (1) for an assumed-rank object that is associated with an assumed-size
11 ! array, the result has the value −1 if DIM is present and equal to the
12 ! rank of ARRAY, and a negative value that is equal to
13 ! PRODUCT ( [ (SIZE (ARRAY, I, KIND), I=1, RANK (ARRAY)) ] )
14 ! if DIM is not present;
15 !
16 ! (2) for an assumed-rank object that is associated with a scalar, the
17 ! result has the value 1.
18 !
19 ! The idea here is that the main program passes some arrays to a test
20 ! subroutine with an assumed-size dummy, which in turn passes that to a
21 ! subroutine with an assumed-rank dummy.
22 !
23 ! This is the polymorphic version of size.f90.
24
25 module m
26 type :: t
27 integer :: id
28 real :: xyz(3)
29 end type
30 end module
31
32 program test
33 use m
34
35 ! Define some arrays for testing.
36 type(t), target :: x1(5)
37 type(t) :: y1(0:9)
38 class(t), pointer :: p1(:)
39 class(t), allocatable :: a1(:)
40 type(t), target :: x3(2,3,4)
41 type(t) :: y3(0:1,-3:-1,4)
42 class(t), pointer :: p3(:,:,:)
43 type(t), allocatable :: a3(:,:,:)
44 type(t) :: x
45
46 ! Test the 1-dimensional arrays.
47 call test1 (x1)
48 call test1 (y1)
49 p1 => x1
50 call test1 (p1)
51 allocate (a1(5))
52 call test1 (a1)
53
54 ! Test the multi-dimensional arrays.
55 call test3 (x3, 1, 2, 1, 3)
56 call test3 (y3, 0, 1, -3, -1)
57 p3 => x3
58 call test3 (p3, 1, 2, 1, 3)
59 allocate (a3(2,3,4))
60 call test3 (a3, 1, 2, 1, 3)
61
62 ! Test scalars.
63 call test0 (x)
64 call test0 (x1(1))
65
66 contains
67
68 subroutine testit (a, r, sizes)
69 use m
70 class(t) :: a(..)
71 integer :: r
72 integer :: sizes(r)
73
74 integer :: totalsize, thissize
75 totalsize = 1
76
77 if (r .ne. rank(a)) stop 101
78
79 do i = 1, r
80 thissize = size (a, i)
81 print *, 'got size ', thissize, ' expected ', sizes(i)
82 if (thissize .ne. sizes(i)) stop 102
83 totalsize = totalsize * thissize
84 end do
85
86 if (size(a) .ne. totalsize) stop 103
87 end subroutine
88
89 subroutine test0 (a)
90 use m
91 class(t) :: a(..)
92
93 if (size (a) .ne. 1) stop 103
94 end subroutine
95
96 subroutine test1 (a)
97 use m
98 class(t) :: a(*)
99
100 integer :: sizes(1)
101 sizes(1) = -1
102 call testit (a, 1, sizes)
103 end subroutine
104
105 subroutine test3 (a, l1, u1, l2, u2)
106 use m
107 integer :: l1, u1, l2, u2
108 class(t) :: a(l1:u1, l2:u2, *)
109
110 integer :: sizes(3)
111 sizes(1) = u1 - l1 + 1
112 sizes(2) = u2 - l2 + 1
113 sizes(3) = -1
114
115 call testit (a, 3, sizes)
116 end subroutine
117
118 end program