Debian Codegraph @

gcc/testsuite/gfortran.dg/contiguous_15.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fdump-tree-original" }
3 !
4 ! PR fortran/97592 - fix argument passing to CONTIGUOUS,TARGET dummy
5 !
6 ! { dg-final { scan-tree-dump-times "_gfortran_internal_pack \\(&b_2d" 1 "original" } }
7 ! { dg-final { scan-tree-dump-times "_gfortran_internal_pack \\(&p1" 3 "original" } }
8 !
9 ! N.B.: there is no reliable count of _gfortran_internal_pack on temporaries parm.*
10
11 program pr97592
12 implicit none
13 integer :: i, k
14 integer, target :: a(10)
15 integer, pointer :: p1(:), p2(:), tgt(:), expect(:)
16 integer, pointer, contiguous :: cp(:)
17 integer, allocatable, target :: b(:)
18
19 !----------------------
20 ! Code from original PR
21 !----------------------
22 call RemappingTest ()
23
24 !---------------------
25 ! Additional 1-d tests
26 !---------------------
27 a = [(i, i=1,size(a))]
28 b = a
29
30 ! Set p1 to an actually contiguous pointer
31 p1(13:) => a(3::2)
32 print *, lbound (p1), ubound (p1), is_contiguous (p1)
33
34 ! non-contiguous pointer actual argument
35 expect => p1
36 call chk_cont (p1)
37
38 expect => p1
39 call chk_tgt_cont (p1)
40
41 expect => p1
42 call chk_ptr (p1, p2)
43 if (any (p2 /= p1)) stop 1
44
45 expect => p1
46 call chk_tgt (p1, p2)
47 if (any (p2 /= p1)) stop 2
48
49 ! non-contiguous target actual argument
50 expect => b(3::2)
51 call chk_tgt_cont (b(3::2))
52
53 expect => b(3::2)
54 call chk_tgt (b(3::2), p2)
55 if (any (p2 /= p1)) stop 3
56
57 expect => b(3::2)
58 call chk_ptr (b(3::2), p2)
59 if (any (p2 /= p1)) stop 4
60
61 ! Set p1 to an actually contiguous pointer
62 cp(17:) => a(3:9:1)
63 p1 => cp
64 print *, lbound (cp), ubound (cp), is_contiguous (cp)
65 print *, lbound (p1), ubound (p1), is_contiguous (p1)
66
67 expect => p1
68 call chk_tgt (p1, p2)
69 if (any (p2 /= cp)) stop 31
70
71 expect => cp
72 call chk_tgt (cp, p2)
73 if (any (p2 /= cp)) stop 32
74
75 expect => cp
76 call chk_tgt_cont (cp, p2)
77 if (any (p2 /= cp)) stop 33
78
79 expect => cp
80 call chk_tgt_expl (cp, p2, size (cp))
81 if (any (p2 /= cp)) stop 34
82
83 ! See F2018:15.5.2.4 and F2018:C.10.4
84 expect => p1
85 call chk_tgt_cont (p1, p2)
86 ! print *, p2
87 if (any (p2 /= cp)) stop 35
88
89 expect => p1
90 call chk_tgt_expl (p1, p2, size (p1))
91 if (any (p2 /= cp)) stop 36
92
93 expect => cp
94 call chk_ptr_cont (cp, p2)
95 if (any (p2 /= cp)) stop 37
96
97 ! Pass array section which is actually contigous
98 k = 1
99 expect => cp(::k)
100 call chk_ptr (cp(::k), p2)
101 if (any (p2 /= cp(::k))) stop 38
102
103 expect => p1(::k)
104 call chk_tgt_cont (p1(::k), p2)
105 if (any (p2 /= p1(::k))) stop 39
106
107 expect => p1(::k)
108 call chk_tgt (p1(::k), p2)
109 if (any (p2 /= p1(::k))) stop 40
110
111 expect => p1(::k)
112 call chk_tgt_expl (p1(::k), p2, size (p1(::k)))
113 if (any (p2 /= p1(::k))) stop 41
114
115 expect => b(3::k)
116 call chk_tgt_cont (b(3::k), p2)
117 if (any (p2 /= b(3::k))) stop 42
118
119 expect => b(3::k)
120 call chk_tgt (b(3::k), p2)
121 if (any (p2 /= b(3::k))) stop 43
122
123 expect => b(3::k)
124 call chk_tgt_expl (b(3::k), p2, size (b(3::k)))
125 if (any (p2 /= b(3::k))) stop 44
126
127 if (any (a /= [(i, i=1,size(a))])) stop 66
128 if (any (a /= b)) stop 77
129 deallocate (b)
130
131 contains
132 ! Contiguous pointer dummy
133 subroutine chk_ptr_cont (x, y)
134 integer, contiguous, pointer, intent(in) :: x(:)
135 integer, pointer, optional :: y(:)
136 print *, lbound (x), ubound (x)
137 if (present (y)) y => x(:)
138 if (associated (expect)) then
139 if (size (x) /= size (expect)) stop 10
140 if (any (x /= expect)) stop 11
141 if (lbound(expect,1) /= 1 .and. &
142 lbound(expect,1) /= lbound (x,1)) stop 20
143 end if
144 end
145
146 ! Pointer dummy
147 subroutine chk_ptr (x, y)
148 integer, pointer, intent(in) :: x(:)
149 integer, pointer, optional :: y(:)
150 print *, lbound (x), ubound (x)
151 if (present (y)) y => x(:)
152 if (associated (expect)) then
153 if (size (x) /= size (expect)) stop 12
154 if (any (x /= expect)) stop 13
155 if (lbound(expect,1) /= 1 .and. &
156 lbound(expect,1) /= lbound (x,1)) stop 22
157 end if
158 end
159
160 ! Dummy with target attribute
161 subroutine chk_tgt_cont (x, y)
162 integer, contiguous, target, intent(in) :: x(:)
163 integer, pointer, optional :: y(:)
164 if (present (y)) y => x(:)
165 if (associated (expect)) then
166 if (size (x) /= size (expect)) stop 14
167 if (any (x /= expect)) stop 15
168 end if
169 end
170
171 subroutine chk_tgt (x, y)
172 integer, target, intent(in) :: x(:)
173 integer, pointer, optional :: y(:)
174 if (present (y)) y => x(:)
175 if (associated (expect)) then
176 if (size (x) /= size (expect)) stop 16
177 if (any (x /= expect)) stop 17
178 end if
179 end
180
181 ! Explicit-shape dummy with target attribute
182 subroutine chk_tgt_expl (x, y, n)
183 integer, intent(in) :: n
184 integer, target, intent(in) :: x(n)
185 integer, pointer, optional :: y(:)
186 if (present (y)) y => x(:)
187 if (associated (expect)) then
188 if (size (x) /= size (expect)) stop 18
189 if (any (x /= expect)) stop 19
190 end if
191 end
192
193 ! Dummy without pointer or target attribute
194 subroutine chk_cont (x)
195 integer, contiguous, intent(in) :: x(:)
196 if (associated (expect)) then
197 if (size (x) /= size (expect)) stop 23
198 if (any (x /= expect)) stop 24
199 end if
200 end
201
202 !------------------------------------------------------------------------
203
204 subroutine RemappingTest ()
205 real, pointer :: B_2D(:,:)
206 real, pointer :: B_3D(:,:,:) => NULL()
207 integer, parameter :: n1=4, n2=4, n3=3
208 !-- Prepare B_2D
209 allocate (B_2D(n1*n2, n3))
210 B_2D = - huge (1.0)
211 if (.not. is_contiguous (B_2D)) stop 101
212 !-- Point B_3D to Storage
213 call SetPointer (B_2D, n1, n2, n3, B_3D)
214 !print *,"is_contiguous (B_3D) =", is_contiguous (B_3D)
215 if (.not. is_contiguous (B_3D)) stop 102
216 !-- Set B_3D
217 B_3D = 2.0
218 !-- See if the result is reflected in Storage
219 if (any (B_2D /= 2.0)) then
220 print *, "B_2D = ", B_2D !-- expect 2.0 for all elements
221 stop 103
222 end if
223 print *,"RemappingTest passed"
224 end
225
226 subroutine SetPointer (C_2D, n1, n2, n3, C_3D)
227 integer, intent(in) :: n1, n2, n3
228 real, target, contiguous :: C_2D(:,:)
229 real, pointer :: C_3D(:,:,:)
230 intent(in) :: C_2D
231 C_3D(1:n1,1:n2,1:n3) => C_2D
232 end
233
234 end