Debian Codegraph @

gcc/testsuite/gfortran.dg/minloc_8.f90

raw
1 ! { dg-do run }
2 !
3 ! PR fortran/90608
4 ! Check the correct behaviour of the inline MINLOC implementation,
5 ! when there is no optional argument.
6
7 program p
8 implicit none
9 integer, parameter :: data5(*) = (/ 8, 2, 7, 2, 9 /)
10 integer, parameter :: data64(*) = (/ 7, 4, 5, 3, 9, 0, 6, 4, &
11 5, 5, 8, 2, 6, 7, 8, 7, &
12 4, 5, 3, 9, 0, 6, 4, 5, &
13 5, 8, 2, 6, 7, 8, 7, 4, &
14 5, 3, 9, 0, 6, 4, 5, 5, &
15 8, 2, 6, 7, 8, 7, 4, 5, &
16 3, 9, 0, 6, 4, 5, 5, 8, &
17 2, 6, 7, 8, 7, 4, 5, 3 /)
18 call check_int_const_shape_rank_1
19 call check_int_const_shape_rank_3
20 call check_int_const_shape_empty_4
21 call check_int_alloc_rank_1
22 call check_int_alloc_rank_3
23 call check_int_alloc_empty_4
24 call check_real_const_shape_rank_1
25 call check_real_const_shape_rank_3
26 call check_real_const_shape_empty_4
27 call check_real_alloc_rank_1
28 call check_real_alloc_rank_3
29 call check_real_alloc_empty_4
30 call check_int_lower_bounds
31 call check_real_lower_bounds
32 call check_dependencies
33 contains
34 subroutine check_int_const_shape_rank_1()
35 integer :: a(5)
36 integer, allocatable :: m(:)
37 a = data5
38 m = minloc(a)
39 if (size(m, dim=1) /= 1) stop 11
40 if (any(m /= (/ 2 /))) stop 12
41 end subroutine
42 subroutine check_int_const_shape_rank_3()
43 integer :: a(4,4,4)
44 integer, allocatable :: m(:)
45 a = reshape(data64, shape(a))
46 m = minloc(a)
47 if (size(m, dim=1) /= 3) stop 21
48 if (any(m /= (/ 2, 2, 1 /))) stop 22
49 end subroutine
50 subroutine check_int_const_shape_empty_4()
51 integer :: a(9,3,0,7)
52 integer, allocatable :: m(:)
53 a = reshape((/ integer:: /), shape(a))
54 m = minloc(a)
55 if (size(m, dim=1) /= 4) stop 31
56 if (any(m /= (/ 0, 0, 0, 0 /))) stop 32
57 end subroutine
58 subroutine check_int_alloc_rank_1()
59 integer, allocatable :: a(:)
60 integer, allocatable :: m(:)
61 allocate(a(5))
62 a(:) = data5
63 m = minloc(a)
64 if (size(m, dim=1) /= 1) stop 41
65 if (any(m /= (/ 2 /))) stop 42
66 end subroutine
67 subroutine check_int_alloc_rank_3()
68 integer, allocatable :: a(:,:,:)
69 integer, allocatable :: m(:)
70 allocate(a(4,4,4))
71 a(:,:,:) = reshape(data64, shape(a))
72 m = minloc(a)
73 if (size(m, dim=1) /= 3) stop 51
74 if (any(m /= (/ 2, 2, 1 /))) stop 52
75 end subroutine
76 subroutine check_int_alloc_empty_4()
77 integer, allocatable :: a(:,:,:,:)
78 integer, allocatable :: m(:)
79 allocate(a(9,3,0,7))
80 a(:,:,:,:) = reshape((/ integer:: /), shape(a))
81 m = minloc(a)
82 if (size(m, dim=1) /= 4) stop 61
83 if (any(m /= (/ 0, 0, 0, 0 /))) stop 62
84 end subroutine
85 subroutine check_real_const_shape_rank_1()
86 real :: a(5)
87 integer, allocatable :: m(:)
88 a = (/ real:: data5 /)
89 m = minloc(a)
90 if (size(m, dim=1) /= 1) stop 71
91 if (any(m /= (/ 2 /))) stop 72
92 end subroutine
93 subroutine check_real_const_shape_rank_3()
94 real :: a(4,4,4)
95 integer, allocatable :: m(:)
96 a = reshape((/ real:: data64 /), shape(a))
97 m = minloc(a)
98 if (size(m, dim=1) /= 3) stop 81
99 if (any(m /= (/ 2, 2, 1 /))) stop 82
100 end subroutine
101 subroutine check_real_const_shape_empty_4()
102 real :: a(9,3,0,7)
103 integer, allocatable :: m(:)
104 a = reshape((/ real:: /), shape(a))
105 m = minloc(a)
106 if (size(m, dim=1) /= 4) stop 91
107 if (any(m /= (/ 0, 0, 0, 0 /))) stop 92
108 end subroutine
109 subroutine check_real_alloc_rank_1()
110 real, allocatable :: a(:)
111 integer, allocatable :: m(:)
112 allocate(a(5))
113 a(:) = (/ real:: data5 /)
114 m = minloc(a)
115 if (size(m, dim=1) /= 1) stop 111
116 if (any(m /= (/ 2 /))) stop 112
117 end subroutine
118 subroutine check_real_alloc_rank_3()
119 real, allocatable :: a(:,:,:)
120 integer, allocatable :: m(:)
121 allocate(a(4,4,4))
122 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
123 m = minloc(a)
124 if (size(m, dim=1) /= 3) stop 121
125 if (any(m /= (/ 2, 2, 1 /))) stop 122
126 end subroutine
127 subroutine check_real_alloc_empty_4()
128 real, allocatable :: a(:,:,:,:)
129 integer, allocatable :: m(:)
130 allocate(a(9,3,0,7))
131 a(:,:,:,:) = reshape((/ real:: /), shape(a))
132 m = minloc(a)
133 if (size(m, dim=1) /= 4) stop 131
134 if (any(m /= (/ 0, 0, 0, 0 /))) stop 132
135 end subroutine
136 subroutine check_int_lower_bounds()
137 integer, allocatable :: a(:,:,:)
138 integer, allocatable :: m(:)
139 allocate(a(3:6,-1:2,4))
140 a(:,:,:) = reshape(data64, shape(a))
141 m = minloc(a)
142 if (size(m, dim=1) /= 3) stop 141
143 if (any(m /= (/ 2, 2, 1 /))) stop 142
144 end subroutine
145 subroutine check_real_lower_bounds()
146 real, allocatable :: a(:,:,:)
147 integer, allocatable :: m(:)
148 allocate(a(3:6,-1:2,4))
149 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
150 m = minloc(a)
151 if (size(m, dim=1) /= 3) stop 151
152 if (any(m /= (/ 2, 2, 1 /))) stop 152
153 end subroutine
154 elemental subroutine set(o, i)
155 integer, intent(out) :: o
156 integer, intent(in) :: i
157 o = i
158 end subroutine
159 subroutine check_dependencies()
160 integer, allocatable :: a(:,:,:)
161 allocate(a(3,3,3))
162 ! Direct assignment
163 a(:,:,:) = reshape(data64(1:27), shape(a))
164 a(1,1,:) = minloc(a)
165 if (any(a(1,1,:) /= (/ 3, 2, 1 /))) stop 171
166 a(:,:,:) = reshape(data64(2:28), shape(a))
167 a(3,3,:) = minloc(a)
168 if (any(a(3,3,:) /= (/ 2, 2, 1 /))) stop 172
169 a(:,:,:) = reshape(data64(3:29), shape(a))
170 a(1,:,1) = minloc(a)
171 if (any(a(1,:,1) /= (/ 1, 2, 1 /))) stop 173
172 a(:,:,:) = reshape(data64(5:31), shape(a))
173 a(2,:,2) = minloc(a)
174 if (any(a(2,:,2) /= (/ 2, 1, 1 /))) stop 174
175 a(:,:,:) = reshape(data64(6:32), shape(a))
176 a(3,:,3) = minloc(a)
177 if (any(a(3,:,3) /= (/ 1, 1, 1 /))) stop 175
178 a(:,:,:) = reshape(data64(7:33), shape(a))
179 a(:,1,1) = minloc(a)
180 if (any(a(:,1,1) /= (/ 3, 2, 2 /))) stop 176
181 a(:,:,:) = reshape(data64(8:34), shape(a))
182 a(:,3,3) = minloc(a)
183 if (any(a(:,3,3) /= (/ 2, 2, 2 /))) stop 177
184 ! Subroutine assignment
185 a(:,:,:) = reshape(data64(9:35), shape(a))
186 call set(a(1,1,:), minloc(a))
187 if (any(a(1,1,:) /= (/ 1, 2, 2 /))) stop 181
188 a(:,:,:) = reshape(data64(10:36), shape(a))
189 call set(a(3,3,:), minloc(a))
190 if (any(a(3,3,:) /= (/ 3, 1, 2 /))) stop 182
191 a(:,:,:) = reshape(data64(11:37), shape(a))
192 call set(a(1,:,1), minloc(a))
193 if (any(a(1,:,1) /= (/ 2, 1, 2 /))) stop 183
194 a(:,:,:) = reshape(data64(12:38), shape(a))
195 call set(a(2,:,2), minloc(a))
196 if (any(a(2,:,2) /= (/ 1, 1, 2 /))) stop 184
197 a(:,:,:) = reshape(data64(13:39), shape(a))
198 call set(a(3,:,3), minloc(a))
199 if (any(a(3,:,3) /= (/ 3, 3, 1 /))) stop 185
200 a(:,:,:) = reshape(data64(14:40), shape(a))
201 call set(a(:,1,1), minloc(a))
202 if (any(a(:,1,1) /= (/ 2, 3, 1 /))) stop 186
203 a(:,:,:) = reshape(data64(15:41), shape(a))
204 call set(a(:,3,3), minloc(a))
205 if (any(a(:,3,3) /= (/ 1, 3, 1 /))) stop 187
206 call set(a(1,:,:), minloc(a, dim=1))
207 end subroutine check_dependencies
208 end program p