Skip to content

Commit d90bbf1

Browse files
authored
[flang] Stricter checking of v_list DIO arguments (#139329)
Catch assumed-rank arguments to defined I/O subroutines, and ensure that v_list dummy arguments are vectors. Fixes #138933.
1 parent 8fc1a64 commit d90bbf1

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

flang/lib/Semantics/check-declarations.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ void CheckHelper::CheckObjectEntity(
11921192
typeName);
11931193
} else if (evaluate::IsAssumedRank(symbol)) {
11941194
SayWithDeclaration(symbol,
1195-
"Assumed Rank entity of %s type is not supported"_err_en_US,
1195+
"Assumed rank entity of %s type is not supported"_err_en_US,
11961196
typeName);
11971197
}
11981198
}
@@ -3420,7 +3420,13 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
34203420
bool CheckHelper::CheckDioDummyIsData(
34213421
const Symbol &subp, const Symbol *arg, std::size_t position) {
34223422
if (arg && arg->detailsIf<ObjectEntityDetails>()) {
3423-
return true;
3423+
if (evaluate::IsAssumedRank(*arg)) {
3424+
messages_.Say(arg->name(),
3425+
"Dummy argument '%s' may not be assumed-rank"_err_en_US, arg->name());
3426+
return false;
3427+
} else {
3428+
return true;
3429+
}
34243430
} else {
34253431
if (arg) {
34263432
messages_.Say(arg->name(),
@@ -3598,9 +3604,10 @@ void CheckHelper::CheckDioVlistArg(
35983604
CheckDioDummyIsDefaultInteger(subp, *arg);
35993605
CheckDioDummyAttrs(subp, *arg, Attr::INTENT_IN);
36003606
const auto *objectDetails{arg->detailsIf<ObjectEntityDetails>()};
3601-
if (!objectDetails || !objectDetails->shape().CanBeAssumedShape()) {
3607+
if (!objectDetails || !objectDetails->shape().CanBeAssumedShape() ||
3608+
objectDetails->shape().Rank() != 1) {
36023609
messages_.Say(arg->name(),
3603-
"Dummy argument '%s' of a defined input/output procedure must be assumed shape"_err_en_US,
3610+
"Dummy argument '%s' of a defined input/output procedure must be assumed shape vector"_err_en_US,
36043611
arg->name());
36053612
}
36063613
}

flang/test/Semantics/io11.f90

+46-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ subroutine formattedReadProc(dtv, unit, iotype, vlist, iostat, iomsg)
342342
end subroutine
343343
end module m15
344344

345-
module m16
345+
module m16a
346346
type,public :: t
347347
integer c
348348
contains
@@ -355,15 +355,58 @@ subroutine formattedReadProc(dtv, unit, iotype, vlist, iostat, iomsg)
355355
class(t), intent(inout) :: dtv
356356
integer, intent(in) :: unit
357357
character(len=*), intent(in) :: iotype
358-
!ERROR: Dummy argument 'vlist' of a defined input/output procedure must be assumed shape
358+
!ERROR: Dummy argument 'vlist' of a defined input/output procedure must be assumed shape vector
359359
integer, intent(in) :: vlist(5)
360360
integer, intent(out) :: iostat
361361
character(len=*), intent(inout) :: iomsg
362+
iostat = 343
363+
stop 'fail'
364+
end subroutine
365+
end module m16a
362366

367+
module m16b
368+
type,public :: t
369+
integer c
370+
contains
371+
procedure, pass :: tbp=>formattedReadProc
372+
generic :: read(formatted) => tbp
373+
end type
374+
private
375+
contains
376+
subroutine formattedReadProc(dtv, unit, iotype, vlist, iostat, iomsg)
377+
class(t), intent(inout) :: dtv
378+
integer, intent(in) :: unit
379+
character(len=*), intent(in) :: iotype
380+
!ERROR: Dummy argument 'vlist' of a defined input/output procedure must be assumed shape vector
381+
integer, intent(in) :: vlist(:,:)
382+
integer, intent(out) :: iostat
383+
character(len=*), intent(inout) :: iomsg
384+
iostat = 343
385+
stop 'fail'
386+
end subroutine
387+
end module m16b
388+
389+
module m16c
390+
type,public :: t
391+
integer c
392+
contains
393+
procedure, pass :: tbp=>formattedReadProc
394+
generic :: read(formatted) => tbp
395+
end type
396+
private
397+
contains
398+
subroutine formattedReadProc(dtv, unit, iotype, vlist, iostat, iomsg)
399+
class(t), intent(inout) :: dtv
400+
integer, intent(in) :: unit
401+
character(len=*), intent(in) :: iotype
402+
!ERROR: Dummy argument 'vlist' may not be assumed-rank
403+
integer, intent(in) :: vlist(..)
404+
integer, intent(out) :: iostat
405+
character(len=*), intent(inout) :: iomsg
363406
iostat = 343
364407
stop 'fail'
365408
end subroutine
366-
end module m16
409+
end module m16c
367410

368411
module m17
369412
! Test the same defined input/output procedure specified as a generic

0 commit comments

Comments
 (0)