Debian Codegraph @

gcc/testsuite/gfortran.dg/assumed_rank_24.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fcheck=all" }
3 module m
4 implicit none (external, type)
5 contains
6 subroutine cl(x)
7 class(*) :: x(..)
8 if (rank(x) /= 1) stop 1
9 if (ubound(x, dim=1) /= -1) stop 2
10 select rank (x)
11 rank (1)
12 select type (x)
13 type is (integer)
14 ! ok
15 class default
16 stop 3
17 end select
18 end select
19 end subroutine
20 subroutine tp(x)
21 type(*) :: x(..)
22 if (rank(x) /= 1) stop 4
23 if (ubound(x, dim=1) /= -1) stop 5
24 end subroutine
25
26 subroutine foo (ccc, ddd, sss, ttt)
27 integer :: sss(*), ttt(*)
28 class(*) :: ccc(*), ddd(*)
29 call cl(sss)
30 call tp(ttt)
31 call cl(ccc)
32 call tp(ddd)
33 end
34
35 subroutine foo2 (ccc, ddd, sss, ttt, ispresent)
36 integer :: sss(*), ttt(*)
37 class(*) :: ccc(*), ddd(*)
38 optional :: ccc, ddd, sss, ttt
39 logical, value :: ispresent
40 if (present(ccc) .neqv. ispresent) stop 6
41 if (present(ccc)) then
42 call cl(sss)
43 call tp(ttt)
44 call cl(ccc)
45 call tp(ddd)
46 end if
47 end
48 end
49
50 module m2
51 implicit none (external, type)
52 contains
53 subroutine cl2(x)
54 class(*), allocatable :: x(..)
55 if (rank(x) /= 1) stop 7
56 if (.not. allocated (x)) &
57 return
58 if (lbound(x, dim=1) /= -2) stop 8
59 if (ubound(x, dim=1) /= -1) stop 9
60 if (size (x, dim=1) /= 2) stop 10
61 select rank (x)
62 rank (1)
63 select type (x)
64 type is (integer)
65 ! ok
66 class default
67 stop 11
68 end select
69 end select
70 end subroutine
71
72 subroutine tp2(x)
73 class(*), pointer :: x(..)
74 if (rank(x) /= 1) stop 12
75 if (.not. associated (x)) &
76 return
77 if (lbound(x, dim=1) /= -2) stop 13
78 if (ubound(x, dim=1) /= -1) stop 14
79 if (size (x, dim=1) /= 2) stop 15
80 select rank (x)
81 rank (1)
82 select type (x)
83 type is (integer)
84 ! ok
85 class default
86 stop 16
87 end select
88 end select
89 end subroutine
90
91 subroutine foo3 (ccc, ddd, sss, ttt)
92 class(*), allocatable :: sss(:)
93 class(*), pointer :: ttt(:)
94 class(*), allocatable :: ccc(:)
95 class(*), pointer :: ddd(:)
96 call cl2(sss)
97 call tp2(ttt)
98 call cl2(ccc)
99 call tp2(ddd)
100 end
101
102 subroutine foo4 (ccc, ddd, sss, ttt, ispresent)
103 class(*), allocatable, optional :: sss(:)
104 class(*), pointer, optional :: ttt(:)
105 class(*), allocatable, optional :: ccc(:)
106 class(*), pointer, optional :: ddd(:)
107 logical, value :: ispresent
108 if (present(ccc) .neqv. ispresent) stop 17
109 if (present(ccc)) then
110 call cl2(sss)
111 call tp2(ttt)
112 call cl2(ccc)
113 call tp2(ddd)
114 end if
115 end
116 end
117
118 use m
119 use m2
120 implicit none (external, type)
121 integer :: a(1),b(1),c(1),d(1)
122 class(*),allocatable :: aa(:),cc(:)
123 class(*),pointer :: bb(:),dd(:)
124 call foo (a,b,c,d)
125 call foo2 (a,b,c,d, .true.)
126 call foo2 (ispresent=.false.)
127
128 nullify(bb,dd)
129 call foo3 (aa,bb,cc,dd)
130 call foo4 (aa,bb,cc,dd, .true.)
131 call foo4 (ispresent=.false.)
132 allocate(integer :: aa(-2:-1), bb(-2:-1), cc(-2:-1), dd(-2:-1))
133 call foo3 (aa,bb,cc,dd)
134 call foo4 (aa,bb,cc,dd, .true.)
135 call foo4 (ispresent=.false.)
136 deallocate(aa,bb,cc,dd)
137 end