1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
4 ! Licensed under the Apache License, Version 2.0 (the "License");
5 ! you may not use this file except in compliance with the License.
6 ! You may obtain a copy of the License at
8 ! http://www.apache.org/licenses/LICENSE-2.0
10 ! Unless required by applicable law or agreed to in writing, software
11 ! distributed under the License is distributed on an "AS IS" BASIS,
12 ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ! See the License for the specific language governing permissions and
14 ! limitations under the License.
16 !Section 11.1.7.4.3, paragraph 2 states:
17 ! Except for the incrementation of the DO variable that occurs in step (3),
18 ! the DO variable shall neither be redefined nor become undefined while the
19 ! DO construct is active.
23 ! Redefinition via intrinsic assignment (section 19.6.5, case (1))
26 !ERROR: Cannot redefine DO variable 'ivar'
30 ! Redefinition in the presence of a construct association
31 associate (avar
=> ivar
)
34 !ERROR: Cannot redefine DO variable 'ivar'
41 ! Redefinition via intrinsic assignment (section 19.6.5, case (1))
42 do concurrent (ivar
= 1:10)
44 !ERROR: Cannot redefine DO variable 'ivar'
58 ! Redefinition via an input statement (section 19.6.5, case (3))
61 !ERROR: Cannot redefine DO variable 'ivar'
65 ! Redefinition via an input statement (section 19.6.5, case (3))
66 do concurrent (ivar
= 1:10)
68 !ERROR: Cannot redefine DO variable 'ivar'
78 ! Redefinition via use as a DO variable (section 19.6.5, case (4))
80 !ERROR: Cannot redefine DO variable 'ivar'
82 !ERROR: Cannot redefine DO variable 'ivar'
89 ! This one's OK, even though we used ivar previously as a DO variable
90 ! since it's not a redefinition
95 ! Redefinition via use as a DO variable (section 19.6.5, case (4))
96 do concurrent (ivar
= 1:10)
97 !ERROR: Cannot redefine DO variable 'ivar'
110 print '(f10.5)', (x(ivar
), ivar
= 1, 10)
112 ! Redefinition via use as a DO variable (section 19.6.5, case (5))
114 !ERROR: Cannot redefine DO variable 'ivar'
115 print '(f10.5)', (x(ivar
), ivar
= 1, 10)
118 ! Redefinition via use as a DO variable (section 19.6.5, case (5))
119 do concurrent (ivar
= 1:10)
120 !ERROR: Cannot redefine DO variable 'ivar'
121 print '(f10.5)', (x(ivar
), ivar
= 1, 10)
131 read (3, '(f10.5)', iostat
= ivar
) x
133 ! Redefinition via use in IOSTAT specifier (section 19.6.5, case (7))
136 !ERROR: Cannot redefine DO variable 'ivar'
137 read (3, '(f10.5)', iostat
= ivar
) x
140 ! Redefinition via use in IOSTAT specifier (section 19.6.5, case (7))
141 do concurrent (ivar
= 1:10)
143 !ERROR: Cannot redefine DO variable 'ivar'
144 read (3, '(f10.5)', iostat
= ivar
) x
151 character (len
=3) :: key
156 read (3, '(a3)', advance
='no', size
= chars
) key
158 ! Redefinition via use in SIZE specifier (section 19.6.5, case (9))
160 !ERROR: Cannot redefine DO variable 'ivar'
161 read (3, '(a3)', advance
='no', size
= ivar
) key
165 ! Redefinition via use in SIZE specifier (section 19.6.5, case (9))
166 do concurrent (ivar
= 1:10)
167 !ERROR: ADVANCE specifier is not allowed in DO CONCURRENT
168 !ERROR: Cannot redefine DO variable 'ivar'
169 read (3, '(a3)', advance
='no', size
= ivar
) key
177 integer :: iostatVar
, nextrecVar
, numberVar
, posVar
, reclVar
, sizeVar
179 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
180 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
182 ! Redefinition via use in IOSTAT specifier (section 19.6.5, case (10))
185 !ERROR: Cannot redefine DO variable 'iostatvar'
186 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
187 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
190 ! Redefinition via use in IOSTAT specifier (section 19.6.5, case (10))
191 do concurrent (iostatVar
= 1:10)
193 !ERROR: Cannot redefine DO variable 'iostatvar'
194 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
195 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
198 ! Redefinition via use in NEXTREC specifier (section 19.6.5, case (10))
201 !ERROR: Cannot redefine DO variable 'nextrecvar'
202 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
203 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
206 ! Redefinition via use in NEXTREC specifier (section 19.6.5, case (10))
207 do concurrent (nextrecVar
= 1:10)
209 !ERROR: Cannot redefine DO variable 'nextrecvar'
210 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
211 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
214 ! Redefinition via use in NUMBER specifier (section 19.6.5, case (10))
217 !ERROR: Cannot redefine DO variable 'numbervar'
218 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
219 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
222 ! Redefinition via use in NUMBER specifier (section 19.6.5, case (10))
223 do concurrent (numberVar
= 1:10)
225 !ERROR: Cannot redefine DO variable 'numbervar'
226 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
227 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
230 ! Redefinition via use in RECL specifier (section 19.6.5, case (10))
233 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
234 !ERROR: Cannot redefine DO variable 'reclvar'
235 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
238 ! Redefinition via use in RECL specifier (section 19.6.5, case (10))
239 do concurrent (reclVar
= 1:10)
241 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
242 !ERROR: Cannot redefine DO variable 'reclvar'
243 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
246 ! Redefinition via use in POS specifier (section 19.6.5, case (10))
249 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
250 !ERROR: Cannot redefine DO variable 'posvar'
251 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
254 ! Redefinition via use in POS specifier (section 19.6.5, case (10))
255 do concurrent (posVar
= 1:10)
257 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
258 !ERROR: Cannot redefine DO variable 'posvar'
259 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
262 ! Redefinition via use in SIZE specifier (section 19.6.5, case (10))
265 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
266 !ERROR: Cannot redefine DO variable 'sizevar'
267 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
270 ! Redefinition via use in SIZE specifier (section 19.6.5, case (10))
271 do concurrent (sizeVar
= 1:10)
273 inquire(3, iostat
=iostatVar
, nextrec
=nextrecVar
, number
=numberVar
, &
274 !ERROR: Cannot redefine DO variable 'sizevar'
275 pos
=posVar
, recl
=reclVar
, size
=sizeVar
)
283 integer, pointer :: ip
285 allocate(ip
, stat
= ivar
)
287 ! Redefinition via a STAT= specifier (section 19.6.5, case (16))
289 !ERROR: Cannot redefine DO variable 'ivar'
290 allocate(ip
, stat
= ivar
)
294 ! Redefinition via a STAT= specifier (section 19.6.5, case (16))
295 do concurrent (ivar
= 1:10)
296 !ERROR: Cannot redefine DO variable 'ivar'
297 allocate(ip
, stat
= ivar
)
307 ! OK since the DO CONCURRENT index-name exists only in the scope of the
308 ! DO CONCURRENT construct
311 do concurrent (ivar
= 1:10)
316 ! OK since the DO CONCURRENT index-name exists only in the scope of the
317 ! DO CONCURRENT construct
318 do concurrent (ivar
= 1:10)
320 do concurrent (ivar
= 1:10)
330 open(file
="abc", newunit
=ivar
)
332 ! Redefinition via NEWUNIT specifier (section 19.6.5, case (29))
335 !ERROR: Cannot redefine DO variable 'ivar'
336 open(file
="abc", newunit
=ivar
)
339 ! Redefinition via NEWUNIT specifier (section 19.6.5, case (29))
340 do concurrent (ivar
= 1:10)
342 !ERROR: Cannot redefine DO variable 'ivar'
343 open(file
="abc", newunit
=ivar
)
350 Integer, allocatable
:: ivar
359 ! Redefinition via deallocation (section 19.6.6, case (10))
362 !ERROR: Cannot redefine DO variable 'ivar'
366 ! This case is not applicable since the version of "ivar" that's inside the
367 ! DO CONCURRENT has the scope of the DO CONCURRENT construct. Within that
368 ! scope, it does not have the "allocatable" attribute, so the following test
369 ! fails because you can only deallocate a variable that's allocatable.
370 do concurrent (ivar
= 1:10)
372 !ERROR: Name in DEALLOCATE statement must have the ALLOCATABLE or POINTER attribute
380 Integer :: ivar
, jvar
382 call intentInSub(jvar
, ivar
)
384 call intentInSub(jvar
, ivar
)
387 call intentOutSub(jvar
, ivar
)
389 !ERROR: Cannot redefine DO variable 'ivar'
390 call intentOutSub(jvar
, ivar
)
393 call intentInOutSub(jvar
, ivar
)
395 !WARNING: Possible redefinition of DO variable 'ivar'
396 call intentInOutSub(jvar
, ivar
)
400 subroutine intentInSub(arg1
, arg2
)
401 integer, intent(in
) :: arg1
402 integer, intent(in
) :: arg2
403 end subroutine intentInSub
405 subroutine intentOutSub(arg1
, arg2
)
406 integer, intent(in
) :: arg1
407 integer, intent(out
) :: arg2
408 end subroutine intentOutSub
410 subroutine intentInOutSub(arg1
, arg2
)
411 integer, intent(in
) :: arg1
412 integer, intent(inout
) :: arg2
413 end subroutine intentInOutSub
419 Integer :: ivar
, jvar
423 jvar
= intentInFunc(ivar
)
426 ! Error for passing a DO variable to an INTENT(OUT) dummy
428 !ERROR: Cannot redefine DO variable 'ivar'
429 jvar
= intentOutFunc(ivar
)
432 ! Error for passing a DO variable to an INTENT(OUT) dummy, more complex
435 !ERROR: Cannot redefine DO variable 'ivar'
436 jvar
= 83 + intentInFunc(intentOutFunc(ivar
))
440 !WARNING: Possible redefinition of DO variable 'ivar'
441 jvar
= intentInOutFunc(ivar
)
445 function intentInFunc(dummyArg
)
446 integer, intent(in
) :: dummyArg
447 integer :: intentInFunc
450 end function intentInFunc
452 function intentOutFunc(dummyArg
)
453 integer, intent(out
) :: dummyArg
454 integer :: intentOutFunc
458 end function intentOutFunc
460 function intentInOutFunc(dummyArg
)
461 integer, intent(inout
) :: dummyArg
462 integer :: intentInOutFunc
465 intentInOutFunc
= 343
466 end function intentInOutFunc