Skip to content

[flang] Fix bogus error on defined I/O procedure. #125898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3368,8 +3368,7 @@ void CheckHelper::CheckDioDummyIsDerived(const Symbol &subp, const Symbol &arg,
}
} else {
messages_.Say(arg.name(),
"Dummy argument '%s' of a defined input/output procedure must have a"
" derived type"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must have a derived type"_err_en_US,
arg.name());
}
}
Expand All @@ -3385,16 +3384,14 @@ void CheckHelper::CheckDioDummyIsDefaultInteger(
}
}
messages_.Say(arg.name(),
"Dummy argument '%s' of a defined input/output procedure"
" must be an INTEGER of default KIND"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must be an INTEGER of default KIND"_err_en_US,
arg.name());
}

void CheckHelper::CheckDioDummyIsScalar(const Symbol &subp, const Symbol &arg) {
if (arg.Rank() > 0 || arg.Corank() > 0) {
messages_.Say(arg.name(),
"Dummy argument '%s' of a defined input/output procedure"
" must be a scalar"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must be a scalar"_err_en_US,
arg.name());
}
}
Expand Down Expand Up @@ -3471,8 +3468,7 @@ void CheckHelper::CheckDioAssumedLenCharacterArg(const Symbol &subp,
context_.defaultKinds().GetDefaultKind(
TypeCategory::Character))) {
messages_.Say(arg->name(),
"Dummy argument '%s' of a defined input/output procedure"
" must be assumed-length CHARACTER of default kind"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must be assumed-length CHARACTER of default kind"_err_en_US,
arg->name());
}
}
Expand All @@ -3485,10 +3481,9 @@ void CheckHelper::CheckDioVlistArg(
CheckDioDummyIsDefaultInteger(subp, *arg);
CheckDioDummyAttrs(subp, *arg, Attr::INTENT_IN);
const auto *objectDetails{arg->detailsIf<ObjectEntityDetails>()};
if (!objectDetails || !objectDetails->shape().CanBeDeferredShape()) {
if (!objectDetails || !objectDetails->shape().CanBeAssumedShape()) {
messages_.Say(arg->name(),
"Dummy argument '%s' of a defined input/output procedure must be"
" deferred shape"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must be assumed shape"_err_en_US,
arg->name());
}
}
Expand All @@ -3503,8 +3498,7 @@ void CheckHelper::CheckDioArgCount(
: 4)};
if (argCount != requiredArgCount) {
SayWithDeclaration(subp,
"Defined input/output procedure '%s' must have"
" %d dummy arguments rather than %d"_err_en_US,
"Defined input/output procedure '%s' must have %d dummy arguments rather than %d"_err_en_US,
subp.name(), requiredArgCount, argCount);
context_.SetError(subp);
}
Expand All @@ -3516,15 +3510,13 @@ void CheckHelper::CheckDioDummyAttrs(
Attrs attrs{arg.attrs()};
if (!attrs.test(goodIntent)) {
messages_.Say(arg.name(),
"Dummy argument '%s' of a defined input/output procedure"
" must have intent '%s'"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure must have intent '%s'"_err_en_US,
arg.name(), AttrToString(goodIntent));
}
attrs = attrs - Attr::INTENT_IN - Attr::INTENT_OUT - Attr::INTENT_INOUT;
if (!attrs.empty()) {
messages_.Say(arg.name(),
"Dummy argument '%s' of a defined input/output procedure may not have"
" any attributes"_err_en_US,
"Dummy argument '%s' of a defined input/output procedure may not have any attributes"_err_en_US,
arg.name());
}
}
Expand All @@ -3537,8 +3529,8 @@ void CheckHelper::CheckDefinedIoProc(const Symbol &symbol,
const auto *binding{ultimate.detailsIf<ProcBindingDetails>()};
const Symbol &specific{*(binding ? &binding->symbol() : &ultimate)};
if (ultimate.attrs().test(Attr::NOPASS)) { // C774
messages_.Say("Defined input/output procedure '%s' may not have NOPASS "
"attribute"_err_en_US,
messages_.Say(
"Defined input/output procedure '%s' may not have NOPASS attribute"_err_en_US,
ultimate.name());
context_.SetError(ultimate);
}
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/io11.f90
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ subroutine formattedReadProc(dtv, unit, iotype, vlist, iostat, iomsg)
class(t), intent(inout) :: dtv
integer, intent(in) :: unit
character(len=*), intent(in) :: iotype
!ERROR: Dummy argument 'vlist' of a defined input/output procedure must be deferred shape
!ERROR: Dummy argument 'vlist' of a defined input/output procedure must be assumed shape
integer, intent(in) :: vlist(5)
integer, intent(out) :: iostat
character(len=*), intent(inout) :: iomsg
Expand Down