Debian Codegraph @

gcc/testsuite/gfortran.dg/actual_array_subref.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-O2 -fcheck=bounds" }
3 !
4 ! PR fortran/119986
5 !
6 ! Check passing of inquiry references of complex arrays and substring
7 ! references of character arrays when these are components of derived types.
8 !
9 ! Extended version of report by Neil Carlson.
10
11 program main
12 implicit none
13 integer :: j
14
15 complex, parameter :: z0(*) = [(cmplx(j,-j),j=1,4)]
16 type :: cx
17 real :: re
18 real :: im
19 end type cx
20 type(cx), parameter :: c0(*) = [(cx (j,-j),j=1,4)]
21
22 type :: my_type
23 complex :: z(4) = z0
24 type(cx) :: c(4) = c0
25 end type my_type
26 type(my_type) :: x
27
28 character(*), parameter :: s0(*) = ["abcd","efgh","ijkl","mnop"]
29 character(*), parameter :: expect(*) = s0(:)(2:3)
30 character(len(s0)) :: s1(4) = s0
31
32 type :: str1
33 character(len(s0)) :: s(4) = s0
34 end type str1
35 type(str1) :: string1
36
37 type :: str2
38 character(:), allocatable :: s(:)
39 end type str2
40 type(str2) :: string2
41
42 integer :: stopcode = 0
43
44 if (len(expect) /= 2) stop 1
45 if (expect(4) /= "no") stop 2
46 if (any(c0 %re /= [ 1, 2, 3, 4])) stop 3
47 if (any(c0 %im /= [-1,-2,-3,-4])) stop 4
48
49 stopcode = 10
50 call fubar ( x%z %re, x%z %im)
51 call fubar ( x%c %re, x%c %im)
52
53 stopcode = 20
54 call fubar ((x%z %re), (x%z %im))
55 call fubar ((x%c %re), (x%c %im))
56
57 stopcode = 30
58 call fubar ([x%z %re], [x%z %im])
59 call fubar ([x%c %re], [x%c %im])
60
61 stopcode = 50
62 call chk ( s0(:)(2:3) )
63 call chk ((s0(:)(2:3)))
64 call chk ([s0(:)(2:3)])
65
66 stopcode = 60
67 call chk ( s1(:)(2:3) )
68 call chk ((s1(:)(2:3)))
69 call chk ([s1(:)(2:3)])
70
71 stopcode = 70
72 call chk ( string1%s(:)(2:3) )
73 call chk ((string1%s(:)(2:3)))
74 call chk ([string1%s(:)(2:3)])
75
76 string2% s = s0
77 if (len(string2%s) /= 4) stop 99
78 stopcode = 80
79 call chk ( string2%s(:)(2:3) )
80 call chk ((string2%s(:)(2:3)))
81 call chk ([string2%s(:)(2:3)])
82 deallocate (string2% s)
83
84 contains
85
86 subroutine fubar(u, v)
87 real, intent(in) :: u(:), v(:)
88 if (any (u /= z0%re)) stop stopcode + 1
89 if (any (v /= z0%im)) stop stopcode + 2
90 if (any (u /= c0%re)) stop stopcode + 3
91 if (any (v /= c0%im)) stop stopcode + 4
92 stopcode = stopcode + 4
93 end subroutine
94
95 subroutine chk (s)
96 character(*), intent(in) :: s(:)
97 if (size(s) /= 4) stop stopcode + 1
98 if (len (s) /= 2) stop stopcode + 2
99 if (any (s /= expect)) stop stopcode + 3
100 stopcode = stopcode + 3
101 end subroutine chk
102
103 end program