Skip to content

Commit 59c77e7

Browse files
authored
[flang] Check I/O implied DO indices better (#159150)
We're not checking READ statement implied DO index variables at all, and we're not checking them for definability.
1 parent fdd989d commit 59c77e7

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

flang/lib/Semantics/check-do-forall.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,14 +1177,27 @@ void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
11771177
}
11781178
}
11791179

1180-
void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
1181-
const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)};
1182-
const parser::Name &name{control.name.thing.thing};
1180+
static void CheckIoImpliedDoIndex(
1181+
SemanticsContext &context, const parser::Name &name) {
11831182
if (name.symbol) {
1184-
context_.CheckIndexVarRedefine(name.source, *name.symbol);
1183+
context.CheckIndexVarRedefine(name.source, *name.symbol);
1184+
if (auto why{WhyNotDefinable(name.source, name.symbol->owner(),
1185+
DefinabilityFlags{}, *name.symbol)}) {
1186+
context.Say(std::move(*why));
1187+
}
11851188
}
11861189
}
11871190

1191+
void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
1192+
CheckIoImpliedDoIndex(context_,
1193+
std::get<parser::IoImpliedDoControl>(outputImpliedDo.t).name.thing.thing);
1194+
}
1195+
1196+
void DoForallChecker::Leave(const parser::InputImpliedDo &inputImpliedDo) {
1197+
CheckIoImpliedDoIndex(context_,
1198+
std::get<parser::IoImpliedDoControl>(inputImpliedDo.t).name.thing.thing);
1199+
}
1200+
11881201
void DoForallChecker::Leave(const parser::StatVariable &statVariable) {
11891202
context_.CheckIndexVarRedefine(statVariable.v.thing.thing);
11901203
}

flang/lib/Semantics/check-do-forall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct ForallStmt;
2626
struct InquireSpec;
2727
struct IoControlSpec;
2828
struct OutputImpliedDo;
29+
struct InputImpliedDo;
2930
struct StatVariable;
3031
} // namespace Fortran::parser
3132

@@ -55,6 +56,7 @@ class DoForallChecker : public virtual BaseChecker {
5556
void Leave(const parser::InquireSpec &);
5657
void Leave(const parser::IoControlSpec &);
5758
void Leave(const parser::OutputImpliedDo &);
59+
void Leave(const parser::InputImpliedDo &);
5860
void Leave(const parser::StatVariable &);
5961

6062
private:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
integer, parameter :: j = 5
3+
real a(5)
4+
!ERROR: 'j' is not a variable
5+
read *, (a(j), j=1, 5)
6+
!ERROR: 'j' is not a variable
7+
print *, (a(j), j=1, 5)
8+
end

0 commit comments

Comments
 (0)