Skip to content

Commit 2c2567d

Browse files
[flang] Fixed a crash with undeclared variable in implicit-do loop (#149513)
Fixed a crash in the following example: ``` subroutine sub() implicit none print *, (i, i = 1, 2) ! Problem: using undefined var in implied-do loop end subroutine sub ``` The error message was already generated, but the compiler crashed before it could display it.
1 parent 5138b61 commit 2c2567d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,9 @@ void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
11801180
void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
11811181
const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)};
11821182
const parser::Name &name{control.name.thing.thing};
1183-
context_.CheckIndexVarRedefine(name.source, *name.symbol);
1183+
if (name.symbol) {
1184+
context_.CheckIndexVarRedefine(name.source, *name.symbol);
1185+
}
11841186
}
11851187

11861188
void DoForallChecker::Leave(const parser::StatVariable &statVariable) {

flang/test/Semantics/resolve40.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ subroutine s12(x)
9696
!BECAUSE: 'x' is an INTENT(IN) dummy argument
9797
read(*,nml=nl)
9898
end
99+
100+
subroutine s13()
101+
implicit none
102+
!ERROR: No explicit type declared for 'i'
103+
!ERROR: No explicit type declared for 'i'
104+
print *, (i, i = 1, 2)
105+
end

0 commit comments

Comments
 (0)