Skip to content

Commit b093477

Browse files
committed
[flang] Stricter checking of v_list DIO arguments
Catch assumed-rank arguments to defined I/O subroutines, and ensure that v_list dummy arguments are vectors. Fixes #138933.
1 parent 51ca3cb commit b093477

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 11 additions & 4 deletions
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
}
@@ -3414,7 +3414,13 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
34143414
bool CheckHelper::CheckDioDummyIsData(
34153415
const Symbol &subp, const Symbol *arg, std::size_t position) {
34163416
if (arg && arg->detailsIf<ObjectEntityDetails>()) {
3417-
return true;
3417+
if (evaluate::IsAssumedRank(*arg)) {
3418+
messages_.Say(arg->name(),
3419+
"Dummy argument '%s' may not be assumed-rank"_err_en_US, arg->name());
3420+
return false;
3421+
} else {
3422+
return true;
3423+
}
34183424
} else {
34193425
if (arg) {
34203426
messages_.Say(arg->name(),
@@ -3592,9 +3598,10 @@ void CheckHelper::CheckDioVlistArg(
35923598
CheckDioDummyIsDefaultInteger(subp, *arg);
35933599
CheckDioDummyAttrs(subp, *arg, Attr::INTENT_IN);
35943600
const auto *objectDetails{arg->detailsIf<ObjectEntityDetails>()};
3595-
if (!objectDetails || !objectDetails->shape().CanBeAssumedShape()) {
3601+
if (!objectDetails || !objectDetails->shape().CanBeAssumedShape() ||
3602+
objectDetails->shape().Rank() != 1) {
35963603
messages_.Say(arg->name(),
3597-
"Dummy argument '%s' of a defined input/output procedure must be assumed shape"_err_en_US,
3604+
"Dummy argument '%s' of a defined input/output procedure must be assumed shape vector"_err_en_US,
35983605
arg->name());
35993606
}
36003607
}

flang/test/Semantics/io11.f90

Lines changed: 46 additions & 3 deletions
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)