Debian Codegraph @

gcc/testsuite/gfortran.dg/maxloc_with_dim_1.f90

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