Debian Codegraph @

gcc/testsuite/gfortran.dg/null_actual_7.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fcheck=bounds" }
3 !
4 ! PR fortran/104819 - passing NULL() to assumed-rank, derived type dummy
5
6 program null_actual
7 implicit none
8 integer :: stop_base
9 type t
10 end type t
11 type(t), pointer :: p2(:,:) => NULL()
12 type(t), allocatable :: a2(:,:)
13 type(t), pointer :: p0 => NULL ()
14 type(t), allocatable :: a0
15
16 ! Basic tests passing unallocated allocatable / disassociated pointer
17 stop_base = 0
18 ! ... to assumed-rank dummy:
19 call chk_t_a (a2)
20 call chk_t_p (p2)
21 call chk_t_a_i (a2)
22 call chk_t_p_i (p2)
23 call opt_t_a (a2)
24 call opt_t_p (p2)
25 call opt_t_a_i (a2)
26 call opt_t_p_i (p2)
27 ! ... to rank-2 dummy:
28 call chk2_t_a (a2)
29 call chk2_t_p (p2)
30 call opt2_t_a (a2)
31 call opt2_t_p (p2)
32 ! ... to rank-0 dummy:
33 stop_base = 60
34 call chk0_t_a (a0)
35 call chk0_t_p (p0)
36 call opt0_t_a (a0)
37 call opt0_t_p (p0)
38 call chk0_t_a_i (a0)
39 call chk0_t_p_i (p0)
40 call opt0_t_a_i (a0)
41 call opt0_t_p_i (p0)
42
43 ! Test NULL with MOLD argument
44 stop_base = 20
45 call chk_t_a (null(a2))
46 call chk_t_p (null(p2))
47 call chk_t_a_i (null(a2))
48 call chk_t_p_i (null(p2))
49 call opt_t_a (null(a2))
50 call opt_t_p (null(p2))
51 call opt_t_a_i (null(a2))
52 call opt_t_p_i (null(p2))
53 call chk2_t_a (null(a2))
54 call chk2_t_p (null(p2))
55 call opt2_t_a (null(a2))
56 call opt2_t_p (null(p2))
57
58 stop_base = 80
59 call chk0_t_a (null(a0))
60 call chk0_t_p (null(p0))
61 call opt0_t_a (null(a0))
62 call opt0_t_p (null(p0))
63 call chk0_t_a_i (null(a0))
64 call chk0_t_p_i (null(p0))
65 call opt0_t_a_i (null(a0))
66 call opt0_t_p_i (null(p0))
67
68 ! Test NULL without MOLD argument
69 stop_base = 40
70 call chk2_t_a (null())
71 call chk2_t_p (null())
72 call opt2_t_a (null())
73 call opt2_t_p (null())
74
75 stop_base = 100
76 call chk0_t_a (null())
77 call chk0_t_p (null())
78 call opt0_t_a (null())
79 call opt0_t_p (null())
80 call chk0_t_a_i (null())
81 call chk0_t_p_i (null())
82 call opt0_t_a_i (null())
83 call opt0_t_p_i (null())
84
85 contains
86 ! Check assumed-rank dummy:
87 subroutine chk_t_a (x)
88 type(t), allocatable :: x(..)
89 if (rank (x) /= 2) stop stop_base + 1
90 if (allocated (x)) stop stop_base + 2
91 end subroutine chk_t_a
92
93 subroutine chk_t_a_i (x)
94 type(t), allocatable, intent(in) :: x(..)
95 if (rank (x) /= 2) stop stop_base + 3
96 if (allocated (x)) stop stop_base + 4
97 end subroutine chk_t_a_i
98
99 subroutine chk_t_p (x)
100 type(t), pointer :: x(..)
101 if (rank (x) /= 2) stop stop_base + 5
102 if (associated (x)) stop stop_base + 6
103 end subroutine chk_t_p
104
105 subroutine chk_t_p_i (x)
106 type(t), pointer, intent(in) :: x(..)
107 if (rank (x) /= 2) stop stop_base + 7
108 if (associated (x)) stop stop_base + 8
109 end subroutine chk_t_p_i
110
111 ! Check assumed-rank optional dummy:
112 subroutine opt_t_a (x)
113 type(t), optional, allocatable :: x(..)
114 if (.not. present (x)) stop stop_base + 11
115 end subroutine opt_t_a
116
117 subroutine opt_t_a_i (x)
118 type(t), optional, allocatable, intent(in) :: x(..)
119 if (.not. present (x)) stop stop_base + 12
120 end subroutine opt_t_a_i
121
122 subroutine opt_t_p (x)
123 type(t), optional, pointer :: x(..)
124 if (.not. present (x)) stop stop_base + 13
125 end subroutine opt_t_p
126
127 subroutine opt_t_p_i (x)
128 type(t), optional, pointer, intent(in) :: x(..)
129 if (.not. present (x)) stop stop_base + 14
130 end subroutine opt_t_p_i
131
132 ! Checks with fixed rank:
133 subroutine chk2_t_a (x)
134 type(t), allocatable :: x(:,:)
135 if (allocated (x)) stop stop_base + 15
136 end subroutine chk2_t_a
137
138 subroutine chk2_t_p (x)
139 type(t), pointer, intent(in) :: x(:,:)
140 if (associated (x)) stop stop_base + 16
141 end subroutine chk2_t_p
142
143 ! Checks with fixed rank optional dummy:
144 subroutine opt2_t_a (x)
145 type(t), optional, allocatable :: x(:,:)
146 if (.not. present (x)) stop stop_base + 17
147 if (allocated (x)) stop stop_base + 18
148 end subroutine opt2_t_a
149
150 subroutine opt2_t_p (x)
151 type(t), optional, pointer, intent(in) :: x(:,:)
152 if (.not. present (x)) stop stop_base + 19
153 if (associated (x)) stop stop_base + 20
154 end subroutine opt2_t_p
155
156 ! Checks for rank-0 dummy:
157 subroutine chk0_t_p (x)
158 type(t), pointer :: x
159 if (associated (x)) stop stop_base + 1
160 end subroutine chk0_t_p
161
162 subroutine chk0_t_p_i (x)
163 type(t), pointer, intent(in) :: x
164 if (associated (x)) stop stop_base + 2
165 end subroutine chk0_t_p_i
166
167 subroutine opt0_t_p (x)
168 type(t), pointer, optional :: x
169 if (.not. present (x)) stop stop_base + 3
170 if (associated (x)) stop stop_base + 4
171 end subroutine opt0_t_p
172
173 subroutine opt0_t_p_i (x)
174 type(t), pointer, optional, intent(in) :: x
175 if (.not. present (x)) stop stop_base + 5
176 if (associated (x)) stop stop_base + 6
177 end subroutine opt0_t_p_i
178
179 subroutine chk0_t_a (x)
180 type(t), allocatable :: x
181 if (allocated (x)) stop stop_base + 7
182 end subroutine chk0_t_a
183
184 subroutine chk0_t_a_i (x)
185 type(t), allocatable, intent(in) :: x
186 if (allocated (x)) stop stop_base + 8
187 end subroutine chk0_t_a_i
188
189 subroutine opt0_t_a (x)
190 type(t), allocatable, optional :: x
191 if (.not. present (x)) stop stop_base + 9
192 if (allocated (x)) stop stop_base + 10
193 end subroutine opt0_t_a
194
195 subroutine opt0_t_a_i (x)
196 type(t), allocatable, optional, intent(in) :: x
197 if (.not. present (x)) stop stop_base + 11
198 if (allocated (x)) stop stop_base + 12
199 end subroutine opt0_t_a_i
200 end