Debian Codegraph @

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

raw
1 ! { dg-do run }
2 !
3 ! TS 29113
4 ! 6.4.3 UBOUND
5 !
6 ! The description of the intrinsic function UBOUND in ISO/IEC
7 ! 1539-1:2010 is changed for an assumed-rank object that is associated
8 ! with an assumed-size array; the result of UBOUND (ARRAY, RANK(ARRAY),
9 ! KIND) has a value equal to LBOUND (ARRAY, RANK (ARRAY), KIND) −2 with
10 ! KIND omitted from LBOUND if it was omitted from UBOUND.
11 !
12 ! NOTE 6.2
13 ! If LBOUND or UBOUND is invoked for an assumed-rank object that is
14 ! associated with a scalar and DIM is absent, the result is a zero-sized
15 ! array. LBOUND or UBOUND cannot be invoked for an assumed-rank object
16 ! that is associated with a scalar if DIM is present because the rank of
17 ! a scalar is zero and DIM must be ≥ 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 like ubound.f90, but using polymorphic arrays instead of integer
24 ! arrays.
25
26 module m
27 type :: t
28 integer :: id
29 real :: xyz(3)
30 end type
31 end module
32
33 program test
34 use m
35
36 ! Define some arrays for testing.
37 type(t), target :: x1(5)
38 type(t) :: y1(0:9)
39 class(t), pointer :: p1(:)
40 class(t), allocatable :: a1(:)
41 type(t), target :: x3(2,3,4)
42 type(t) :: y3(0:1,-3:-1,4)
43 class(t), pointer :: p3(:,:,:)
44 type(t), allocatable :: a3(:,:,:)
45 type(t) :: x
46
47 ! Test the 1-dimensional arrays.
48 call test1 (x1)
49 call testit2(x1, shape(x1))
50 call test1 (y1)
51 call testit2(y1, shape(y1))
52 p1 => x1
53 call testit2(p1, shape(p1))
54 call testit2p(p1, lbound(p1), shape(p1))
55 call test1 (p1)
56 p1(77:) => x1
57 call testit2p(p1, [77], shape(p1))
58 allocate (a1(5))
59 call testit2(a1, shape(a1))
60 call testit2a(a1, lbound(a1), shape(a1))
61 call test1 (a1)
62 deallocate(a1)
63 allocate (a1(-38:5))
64 call test1 (a1)
65 call testit2(a1, shape(a1))
66 call testit2a(a1, [-38], shape(a1))
67
68 ! Test the multi-dimensional arrays.
69 call test3 (x3, 1, 2, 1, 3)
70 call test3 (y3, 0, 1, -3, -1)
71 p3 => x3
72 call test3 (p3, 1, 2, 1, 3)
73 allocate (a3(2,3,4))
74 call test3 (a3, 1, 2, 1, 3)
75
76 ! Test some scalars.
77 call test0 (x)
78 call test0 (x1(1))
79
80 contains
81
82 subroutine testit (a)
83 use m
84 class(t) :: a(..)
85 integer :: r
86 r = rank(a)
87 if (any (lbound (a) .ne. 1)) stop 101
88 if (ubound (a, r) .ne. -1) stop 102
89 end subroutine
90
91 subroutine testit2(a, shape)
92 use m
93 class(t) :: a(..)
94 integer :: shape(:)
95 if (rank(a) /= size(shape)) stop 111
96 if (any (lbound(a) /= 1)) stop 112
97 if (any (ubound(a) /= shape)) stop 113
98 end subroutine
99
100 subroutine testit2a(a,lbound2, shape2)
101 use m
102 class(t), allocatable :: a(..)
103 integer :: lbound2(:), shape2(:)
104 if (rank(a) /= size(shape2)) stop 121
105 if (any (lbound(a) /= lbound2)) stop 122
106 if (any (ubound(a) /= lbound2 + shape2 - 1)) stop 123
107 if (any (shape(a) /= shape2)) stop 124
108 if (sum (shape(a)) /= size(a)) stop 125
109 end subroutine
110
111 subroutine testit2p(a, lbound2, shape2)
112 use m
113 class(t), pointer :: a(..)
114 integer :: lbound2(:), shape2(:)
115 if (rank(a) /= size(shape2)) stop 131
116 if (any (lbound(a) /= lbound2)) stop 132
117 if (any (ubound(a) /= lbound2 + shape2 - 1)) stop 133
118 if (any (shape(a) /= shape2)) stop 134
119 if (sum (shape(a)) /= size(a)) stop 135
120 end subroutine
121
122 subroutine test0 (a)
123 use m
124 class(t) :: a(..)
125 if (rank (a) .ne. 0) stop 141
126 if (size (lbound (a)) .ne. 0) stop 142
127 if (size (ubound (a)) .ne. 0) stop 143
128 end subroutine
129
130 subroutine test1 (a)
131 use m
132 class(t) :: a(*)
133
134 call testit (a)
135 end subroutine
136
137 subroutine test3 (a, l1, u1, l2, u2)
138 use m
139 integer :: l1, u1, l2, u2
140 class(t) :: a(l1:u1, l2:u2, *)
141
142 call testit (a)
143 end subroutine
144
145 end program