Debian Codegraph @

gcc/testsuite/gfortran.dg/bind_c_char_10.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fdump-tree-original" }
3
4 ! F2018 - examples with array descriptor
5
6 module m
7 use iso_c_binding, only: c_char
8 implicit none (type, external)
9
10 contains
11
12 ! Assumed-shape array, nonallocatable/nonpointer
13
14 subroutine as1 (x1) bind(C)
15 character(kind=c_char, len=1) :: x1(:)
16 if (size(x1) /= 6) stop
17 if (len(x1) /= 1) stop
18 if (any (x1 /= ['g', &
19 'd', &
20 'f', &
21 's', &
22 '3', &
23 '5'])) stop 1
24 x1 = ['1', &
25 'h', &
26 'f', &
27 '3', &
28 '4', &
29 'h']
30 end
31
32 subroutine as2 (x2) bind(C)
33 character(kind=c_char, len=2) :: x2(:)
34 if (size(x2) /= 6) stop
35 if (len(x2) /= 2) stop
36 if (any (x2 /= ['ab', &
37 'fd', &
38 'D4', &
39 '54', &
40 'ga', &
41 'hg'])) stop
42 x2 = ['ab', &
43 'hd', &
44 'fj', &
45 'a4', &
46 '4a', &
47 'hf']
48 end
49
50 subroutine as3 (xn, n) bind(C)
51 integer :: n
52 character(kind=c_char, len=n) :: xn(:)
53 if (size(xn) /= 6) stop
54 if (len(xn) /= 5) stop
55 if (any (xn /= ['DDGhf', &
56 'hdrh$', &
57 'fDGSl', &
58 'DFHs3', &
59 '43grG', &
60 'hFG$k'])) stop
61 xn = ['FDGhf', &
62 'hdrhg', &
63 'fDgFl', &
64 'DFHs3', &
65 '4a54G', &
66 'hSs6k']
67 end
68
69 subroutine as4 (xstar) bind(C)
70 character(kind=c_char, len=*) :: xstar(:)
71 if (size(xstar) /= 6) stop
72 if (len(xstar) /= 5) stop
73 if (any (xstar /= ['DDGhf', &
74 'hdrh$', &
75 'fDGSl', &
76 'DFHs3', &
77 '43grG', &
78 'hFG$k'])) stop
79 xstar = ['FDGhf', &
80 'hdrhg', &
81 'fDgFl', &
82 'DFHs3', &
83 '4a54G', &
84 'hSs6k']
85 end
86
87 ! Assumed-rank array, nonallocatable/nonpointer
88
89 subroutine ar1 (x1) bind(C)
90 character(kind=c_char, len=1) :: x1(..)
91 if (size(x1) /= 6) stop
92 if (len(x1) /= 1) stop
93 select rank(x1)
94 rank(1)
95 if (any (x1 /= ['g', &
96 'd', &
97 'f', &
98 's', &
99 '3', &
100 '5'])) stop
101 x1 = ['1', &
102 'h', &
103 'f', &
104 '3', &
105 '4', &
106 'h']
107 rank default
108 stop
109 end select
110 end
111
112 subroutine ar2 (x2) bind(C)
113 character(kind=c_char, len=2) :: x2(..)
114 if (size(x2) /= 6) stop
115 if (len(x2) /= 2) stop
116 select rank(x2)
117 rank(1)
118 if (any (x2 /= ['ab', &
119 'fd', &
120 'D4', &
121 '54', &
122 'ga', &
123 'hg'])) stop
124 x2 = ['ab', &
125 'hd', &
126 'fj', &
127 'a4', &
128 '4a', &
129 'hf']
130 rank default
131 stop
132 end select
133 end
134
135 subroutine ar3 (xn, n) bind(C)
136 integer :: n
137 character(len=n) :: xn(..)
138 if (size(xn) /= 6) stop
139 if (len(xn) /= 5) stop
140 select rank(xn)
141 rank(1)
142 if (any (xn /= ['DDGhf', &
143 'hdrh$', &
144 'fDGSl', &
145 'DFHs3', &
146 '43grG', &
147 'hFG$k'])) stop
148 xn = ['FDGhf', &
149 'hdrhg', &
150 'fDgFl', &
151 'DFHs3', &
152 '4a54G', &
153 'hSs6k']
154 rank default
155 stop
156 end select
157 end
158
159 subroutine ar4 (xstar) bind(C)
160 character(kind=c_char, len=*) :: xstar(..)
161 if (size(xstar) /= 6) stop
162 if (len(xstar) /= 5) stop
163 select rank(xstar)
164 rank(1)
165 if (any (xstar /= ['DDGhf', &
166 'hdrh$', &
167 'fDGSl', &
168 'DFHs3', &
169 '43grG', &
170 'hFG$k'])) stop
171 xstar = ['FDGhf', &
172 'hdrhg', &
173 'fDgFl', &
174 'DFHs3', &
175 '4a54G', &
176 'hSs6k']
177 rank default
178 stop
179 end select
180 end
181
182 ! ALLOCATABLE
183
184 ! Assumed-shape array, allocatable
185
186 subroutine a5a (xcolon) bind(C)
187 character(kind=c_char, len=:), allocatable :: xcolon(:)
188 if (.not. allocated (xcolon)) stop
189 if (size(xcolon) /= 6) stop
190 if (len(xcolon) /= 5) stop
191 if (any (xcolon /= ['DDGhf', &
192 'hdrh$', &
193 'fDGSl', &
194 'DFHs3', &
195 '43grG', &
196 'hFG$k'])) stop
197 xcolon = ['FDGhf', &
198 'hdrhg', &
199 'fDgFl', &
200 'DFHs3', &
201 '4a54G', &
202 'hSs6k']
203 end
204
205 ! Assumed-rank array, allocatable
206
207 subroutine a5ar (xcolon) bind(C)
208 character(kind=c_char, len=:), allocatable :: xcolon(..)
209 if (.not. allocated (xcolon)) stop
210 if (size(xcolon) /= 6) stop
211 if (len(xcolon) /= 5) stop
212 select rank(xcolon)
213 rank(1)
214 if (any (xcolon /= ['DDGhf', &
215 'hdrh$', &
216 'fDGSl', &
217 'DFHs3', &
218 '43grG', &
219 'hFG$k'])) stop
220 xcolon = ['FDGhf', &
221 'hdrhg', &
222 'fDgFl', &
223 'DFHs3', &
224 '4a54G', &
225 'hSs6k']
226 rank default
227 stop
228 end select
229 end
230
231 ! POINTER
232 ! Assumed-shape array, pointer
233
234 subroutine a5p (xcolon) bind(C)
235 character(kind=c_char, len=:), pointer :: xcolon(:)
236 if (.not. associated (xcolon)) stop
237 if (size(xcolon) /= 6) stop
238 if (len(xcolon) /= 5) stop
239 if (any (xcolon /= ['DDGhf', &
240 'hdrh$', &
241 'fDGSl', &
242 'DFHs3', &
243 '43grG', &
244 'hFG$k'])) stop
245 xcolon = ['FDGhf', &
246 'hdrhg', &
247 'fDgFl', &
248 'DFHs3', &
249 '4a54G', &
250 'hSs6k']
251 end
252
253 ! Assumed-rank array, pointer
254
255 subroutine a5pr (xcolon) bind(C)
256 character(kind=c_char, len=:), pointer :: xcolon(..)
257 if (.not. associated (xcolon)) stop
258 if (size(xcolon) /= 6) stop
259 if (len(xcolon) /= 5) stop
260 select rank(xcolon)
261 rank(1)
262 if (any (xcolon /= ['DDGhf', &
263 'hdrh$', &
264 'fDGSl', &
265 'DFHs3', &
266 '43grG', &
267 'hFG$k'])) stop
268 xcolon = ['FDGhf', &
269 'hdrhg', &
270 'fDgFl', &
271 'DFHs3', &
272 '4a54G', &
273 'hSs6k']
274 rank default
275 stop
276 end select
277 end
278 end module m
279
280 program main
281 use m
282 implicit none (type, external)
283 character(kind=c_char, len=1) :: str1a6(6)
284 character(kind=c_char, len=2) :: str2a6(6)
285 character(kind=c_char, len=5) :: str5a6(6)
286
287 character(kind=c_char, len=:), allocatable :: astr5a6(:)
288 character(kind=c_char, len=:), pointer :: pstr5a6(:)
289
290 allocate (character(kind=c_char, len=5) :: astr5a6(6), pstr5a6(6))
291
292 ! assumed shape - with array descriptor
293
294 str1a6 = ['g', &
295 'd', &
296 'f', &
297 's', &
298 '3', &
299 '5']
300 call as1 (str1a6)
301 if (any (str1a6 /= ['1', &
302 'h', &
303 'f', &
304 '3', &
305 '4', &
306 'h'])) stop
307 str2a6 = ['ab', &
308 'fd', &
309 'D4', &
310 '54', &
311 'ga', &
312 'hg']
313 call as2 (str2a6)
314 if (any (str2a6 /= ['ab', &
315 'hd', &
316 'fj', &
317 'a4', &
318 '4a', &
319 'hf'])) stop
320
321 str5a6 = ['DDGhf', &
322 'hdrh$', &
323 'fDGSl', &
324 'DFHs3', &
325 '43grG', &
326 'hFG$k']
327 call as3 (str5a6, 5)
328 if (any (str5a6 /= ['FDGhf', &
329 'hdrhg', &
330 'fDgFl', &
331 'DFHs3', &
332 '4a54G', &
333 'hSs6k'])) stop
334
335 str5a6 = ['DDGhf', &
336 'hdrh$', &
337 'fDGSl', &
338 'DFHs3', &
339 '43grG', &
340 'hFG$k']
341 call as4 (str5a6)
342 if (any (str5a6 /= ['FDGhf', &
343 'hdrhg', &
344 'fDgFl', &
345 'DFHs3', &
346 '4a54G', &
347 'hSs6k'])) stop
348
349 ! assumed rank - with array descriptor
350
351 str1a6 = ['g', &
352 'd', &
353 'f', &
354 's', &
355 '3', &
356 '5']
357 call ar1 (str1a6)
358 if (any (str1a6 /= ['1', &
359 'h', &
360 'f', &
361 '3', &
362 '4', &
363 'h'])) stop
364 str2a6 = ['ab', &
365 'fd', &
366 'D4', &
367 '54', &
368 'ga', &
369 'hg']
370 call ar2 (str2a6)
371 if (any (str2a6 /= ['ab', &
372 'hd', &
373 'fj', &
374 'a4', &
375 '4a', &
376 'hf'])) stop
377
378 str5a6 = ['DDGhf', &
379 'hdrh$', &
380 'fDGSl', &
381 'DFHs3', &
382 '43grG', &
383 'hFG$k']
384 call ar3 (str5a6, 5)
385 if (any (str5a6 /= ['FDGhf', &
386 'hdrhg', &
387 'fDgFl', &
388 'DFHs3', &
389 '4a54G', &
390 'hSs6k'])) stop
391
392
393 str5a6 = ['DDGhf', &
394 'hdrh$', &
395 'fDGSl', &
396 'DFHs3', &
397 '43grG', &
398 'hFG$k']
399 call ar4 (str5a6)
400 if (any (str5a6 /= ['FDGhf', &
401 'hdrhg', &
402 'fDgFl', &
403 'DFHs3', &
404 '4a54G', &
405 'hSs6k'])) stop
406
407 ! allocatable - with array descriptor
408 astr5a6(:) = ['DDGhf', &
409 'hdrh$', &
410 'fDGSl', &
411 'DFHs3', &
412 '43grG', &
413 'hFG$k']
414 call a5a (astr5a6)
415 if (any (astr5a6 /= ['FDGhf', &
416 'hdrhg', &
417 'fDgFl', &
418 'DFHs3', &
419 '4a54G', &
420 'hSs6k'])) stop
421
422 astr5a6(:) = ['DDGhf', &
423 'hdrh$', &
424 'fDGSl', &
425 'DFHs3', &
426 '43grG', &
427 'hFG$k']
428 call a5ar (astr5a6)
429 if (any (astr5a6 /= ['FDGhf', &
430 'hdrhg', &
431 'fDgFl', &
432 'DFHs3', &
433 '4a54G', &
434 'hSs6k'])) stop
435
436
437 ! pointer - with array descriptor
438 pstr5a6 = ['DDGhf', &
439 'hdrh$', &
440 'fDGSl', &
441 'DFHs3', &
442 '43grG', &
443 'hFG$k']
444 call a5p (pstr5a6)
445 if (any (pstr5a6 /= ['FDGhf', &
446 'hdrhg', &
447 'fDgFl', &
448 'DFHs3', &
449 '4a54G', &
450 'hSs6k'])) stop
451
452 pstr5a6 = ['DDGhf', &
453 'hdrh$', &
454 'fDGSl', &
455 'DFHs3', &
456 '43grG', &
457 'hFG$k']
458 call a5pr (pstr5a6)
459 if (any (pstr5a6 /= ['FDGhf', &
460 'hdrhg', &
461 'fDgFl', &
462 'DFHs3', &
463 '4a54G', &
464 'hSs6k'])) stop
465 deallocate (astr5a6, pstr5a6)
466 end
467
468 ! All arguments shall use array descriptors
469 ! { dg-final { scan-tree-dump-times "void as1 \\(struct CFI_cdesc_t01 & restrict _x1\\)" 1 "original" } }
470 ! { dg-final { scan-tree-dump-times "void as2 \\(struct CFI_cdesc_t01 & restrict _x2\\)" 1 "original" } }
471 ! { dg-final { scan-tree-dump-times "void as3 \\(struct CFI_cdesc_t01 & restrict _xn, integer\\(kind=4\\) & restrict n\\)" 1 "original" } }
472 ! { dg-final { scan-tree-dump-times "void as4 \\(struct CFI_cdesc_t01 & restrict _xstar\\)" 1 "original" } }
473 ! { dg-final { scan-tree-dump-times "void ar1 \\(struct CFI_cdesc_t & restrict _x1\\)" 1 "original" } }
474 ! { dg-final { scan-tree-dump-times "void ar2 \\(struct CFI_cdesc_t & restrict _x2\\)" 1 "original" } }
475 ! { dg-final { scan-tree-dump-times "void ar3 \\(struct CFI_cdesc_t & restrict _xn, integer\\(kind=4\\) & restrict n\\)" 1 "original" } }
476 ! { dg-final { scan-tree-dump-times "void ar4 \\(struct CFI_cdesc_t & restrict _xstar\\)" 1 "original" } }
477 ! { dg-final { scan-tree-dump-times "void a5ar \\(struct CFI_cdesc_t & restrict _xcolon\\)" 1 "original" } }
478 ! { dg-final { scan-tree-dump-times "void a5a \\(struct CFI_cdesc_t01 & restrict _xcolon\\)" 1 "original" } }
479 ! { dg-final { scan-tree-dump-times "void a5pr \\(struct CFI_cdesc_t & _xcolon\\)" 1 "original" } }
480 ! { dg-final { scan-tree-dump-times "void a5p \\(struct CFI_cdesc_t01 & _xcolon\\)" 1 "original" } }
481