dosemantics12.f90
12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
! RUN: %S/test_errors.sh %s %t %f18
! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
!Section 11.1.7.4.3, paragraph 2 states:
! Except for the incrementation of the DO variable that occurs in step (3),
! the DO variable shall neither be redefined nor become undefined while the
! DO construct is active.
subroutine s1()
! Redefinition via intrinsic assignment (section 19.6.5, case (1))
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
ivar = 99
end do
! Redefinition in the presence of a construct association
associate (avar => ivar)
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
avar = 99
end do
end associate
ivar = 99
! Redefinition via intrinsic assignment (section 19.6.5, case (1))
do concurrent (ivar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
ivar = 99
end do
ivar = 99
end subroutine s1
subroutine s2()
integer :: ivar
read '(I10)', ivar
! Redefinition via an input statement (section 19.6.5, case (3))
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
read '(I10)', ivar
end do
! Redefinition via an input statement (section 19.6.5, case (3))
do concurrent (ivar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
read '(I10)', ivar
end do
end subroutine s2
subroutine s3()
integer :: ivar
! Redefinition via use as a DO variable (section 19.6.5, case (4))
do ivar = 1,10
!ERROR: Cannot redefine DO variable 'ivar'
do ivar = 1,20
!ERROR: Cannot redefine DO variable 'ivar'
do ivar = 1,30
print *, "hello"
end do
end do
end do
! This one's OK, even though we used ivar previously as a DO variable
! since it's not a redefinition
do ivar = 1,40
print *, "hello"
end do
! Redefinition via use as a DO variable (section 19.6.5, case (4))
do concurrent (ivar = 1:10)
!ERROR: Cannot redefine DO variable 'ivar'
do ivar = 1,20
print *, "hello"
end do
end do
end subroutine s3
subroutine s4()
integer :: ivar
real :: x(10)
print '(f10.5)', (x(ivar), ivar = 1, 10)
! Redefinition via use as a DO variable (section 19.6.5, case (5))
do ivar = 1,20
!ERROR: Cannot redefine DO variable 'ivar'
print '(f10.5)', (x(ivar), ivar = 1, 10)
end do
! Redefinition via use as a DO variable (section 19.6.5, case (5))
do concurrent (ivar = 1:10)
!ERROR: Cannot redefine DO variable 'ivar'
print '(f10.5)', (x(ivar), ivar = 1, 10)
end do
end subroutine s4
subroutine s5()
integer :: ivar
real :: x
read (3, '(f10.5)', iostat = ivar) x
! Redefinition via use in IOSTAT specifier (section 19.6.5, case (7))
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
read (3, '(f10.5)', iostat = ivar) x
end do
! Redefinition via use in IOSTAT specifier (section 19.6.5, case (7))
do concurrent (ivar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
read (3, '(f10.5)', iostat = ivar) x
end do
end subroutine s5
subroutine s6()
character (len=3) :: key
integer :: chars
integer :: ivar
real :: x
read (3, '(a3)', advance='no', size = chars) key
! Redefinition via use in SIZE specifier (section 19.6.5, case (9))
do ivar = 1,20
!ERROR: Cannot redefine DO variable 'ivar'
read (3, '(a3)', advance='no', size = ivar) key
print *, "hello"
end do
! Redefinition via use in SIZE specifier (section 19.6.5, case (9))
do concurrent (ivar = 1:10)
!ERROR: ADVANCE specifier is not allowed in DO CONCURRENT
!ERROR: Cannot redefine DO variable 'ivar'
read (3, '(a3)', advance='no', size = ivar) key
print *, "hello"
end do
end subroutine s6
subroutine s7()
integer :: iostatVar, nextrecVar, numberVar, posVar, reclVar, sizeVar
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
! Redefinition via use in IOSTAT specifier (section 19.6.5, case (10))
do iostatVar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'iostatvar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in IOSTAT specifier (section 19.6.5, case (10))
do concurrent (iostatVar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'iostatvar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in NEXTREC specifier (section 19.6.5, case (10))
do nextrecVar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'nextrecvar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in NEXTREC specifier (section 19.6.5, case (10))
do concurrent (nextrecVar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'nextrecvar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in NUMBER specifier (section 19.6.5, case (10))
do numberVar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'numbervar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in NUMBER specifier (section 19.6.5, case (10))
do concurrent (numberVar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'numbervar'
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in RECL specifier (section 19.6.5, case (10))
do reclVar = 1,20
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'reclvar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in RECL specifier (section 19.6.5, case (10))
do concurrent (reclVar = 1:10)
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'reclvar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in POS specifier (section 19.6.5, case (10))
do posVar = 1,20
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'posvar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in POS specifier (section 19.6.5, case (10))
do concurrent (posVar = 1:10)
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'posvar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in SIZE specifier (section 19.6.5, case (10))
do sizeVar = 1,20
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'sizevar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
! Redefinition via use in SIZE specifier (section 19.6.5, case (10))
do concurrent (sizeVar = 1:10)
print *, "hello"
inquire(3, iostat=iostatVar, nextrec=nextrecVar, number=numberVar, &
!ERROR: Cannot redefine DO variable 'sizevar'
pos=posVar, recl=reclVar, size=sizeVar)
end do
end subroutine s7
subroutine s8()
Integer :: ivar
integer, pointer :: ip
allocate(ip, stat = ivar)
! Redefinition via a STAT= specifier (section 19.6.5, case (16))
do ivar = 1,20
!ERROR: Cannot redefine DO variable 'ivar'
allocate(ip, stat = ivar)
print *, "hello"
end do
! Redefinition via a STAT= specifier (section 19.6.5, case (16))
do concurrent (ivar = 1:10)
!ERROR: Cannot redefine DO variable 'ivar'
allocate(ip, stat = ivar)
print *, "hello"
end do
end subroutine s8
subroutine s9()
Integer :: ivar
! OK since the DO CONCURRENT index-name exists only in the scope of the
! DO CONCURRENT construct
do ivar = 1,20
print *, "hello"
do concurrent (ivar = 1:10)
print *, "hello"
end do
end do
! OK since the DO CONCURRENT index-name exists only in the scope of the
! DO CONCURRENT construct
do concurrent (ivar = 1:10)
print *, "hello"
do concurrent (ivar = 1:10)
print *, "hello"
end do
end do
end subroutine s9
subroutine s10()
Integer :: ivar
open(file="abc", newunit=ivar)
! Redefinition via NEWUNIT specifier (section 19.6.5, case (29))
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
open(file="abc", newunit=ivar)
end do
! Redefinition via NEWUNIT specifier (section 19.6.5, case (29))
do concurrent (ivar = 1:10)
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
open(file="abc", newunit=ivar)
end do
end subroutine s10
subroutine s11()
Integer, allocatable :: ivar
allocate(ivar)
! This look is OK
do ivar = 1,20
print *, "hello"
end do
! Redefinition via deallocation (section 19.6.6, case (10))
do ivar = 1,20
print *, "hello"
!ERROR: Cannot redefine DO variable 'ivar'
deallocate(ivar)
end do
! This case is not applicable since the version of "ivar" that's inside the
! DO CONCURRENT has the scope of the DO CONCURRENT construct. Within that
! scope, it does not have the "allocatable" attribute, so the following test
! fails because you can only deallocate a variable that's allocatable.
do concurrent (ivar = 1:10)
print *, "hello"
!ERROR: name in DEALLOCATE statement must have the ALLOCATABLE or POINTER attribute
deallocate(ivar)
end do
end subroutine s11
subroutine s12()
Integer :: ivar, jvar
call intentInSub(jvar, ivar)
do ivar = 1,10
call intentInSub(jvar, ivar)
end do
call intentOutSub(jvar, ivar)
do ivar = 1,10
!ERROR: Cannot redefine DO variable 'ivar'
call intentOutSub(jvar, ivar)
end do
call intentInOutSub(jvar, ivar)
do ivar = 1,10
call intentInOutSub(jvar, ivar)
end do
contains
subroutine intentInSub(arg1, arg2)
integer, intent(in) :: arg1
integer, intent(in) :: arg2
end subroutine intentInSub
subroutine intentOutSub(arg1, arg2)
integer, intent(in) :: arg1
integer, intent(out) :: arg2
end subroutine intentOutSub
subroutine intentInOutSub(arg1, arg2)
integer, intent(in) :: arg1
integer, intent(inout) :: arg2
end subroutine intentInOutSub
end subroutine s12
subroutine s13()
Integer :: ivar, jvar
! This one is OK
do ivar = 1, 10
jvar = intentInFunc(ivar)
end do
! Error for passing a DO variable to an INTENT(OUT) dummy
do ivar = 1, 10
!ERROR: Cannot redefine DO variable 'ivar'
jvar = intentOutFunc(ivar)
end do
! Error for passing a DO variable to an INTENT(OUT) dummy, more complex
! expression
do ivar = 1, 10
!ERROR: Cannot redefine DO variable 'ivar'
jvar = 83 + intentInFunc(intentOutFunc(ivar))
end do
! Warning for passing a DO variable to an INTENT(INOUT) dummy
do ivar = 1, 10
jvar = intentInOutFunc(ivar)
end do
contains
function intentInFunc(dummyArg)
integer, intent(in) :: dummyArg
integer :: intentInFunc
intentInFunc = 343
end function intentInFunc
function intentOutFunc(dummyArg)
integer, intent(out) :: dummyArg
integer :: intentOutFunc
dummyArg = 216
intentOutFunc = 343
end function intentOutFunc
function intentInOutFunc(dummyArg)
integer, intent(inout) :: dummyArg
integer :: intentInOutFunc
dummyArg = 216
intentInOutFunc = 343
end function intentInOutFunc
end subroutine s13