[flang-commits] [flang] 2c2567d - [flang] Fixed a crash with undeclared variable in implicit-do loop (#149513)
via flang-commits
flang-commits at lists.llvm.org
Fri Jul 18 09:58:13 PDT 2025
Author: Eugene Epshteyn
Date: 2025-07-18T12:58:09-04:00
New Revision: 2c2567da95c64ee1ed9104ee2539894242922b83
URL: https://github.com/llvm/llvm-project/commit/2c2567da95c64ee1ed9104ee2539894242922b83
DIFF: https://github.com/llvm/llvm-project/commit/2c2567da95c64ee1ed9104ee2539894242922b83.diff
LOG: [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.
Added:
Modified:
flang/lib/Semantics/check-do-forall.cpp
flang/test/Semantics/resolve40.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index cc1d4bf58745a..e258df86a4b1c 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -1180,7 +1180,9 @@ void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)};
const parser::Name &name{control.name.thing.thing};
- context_.CheckIndexVarRedefine(name.source, *name.symbol);
+ if (name.symbol) {
+ context_.CheckIndexVarRedefine(name.source, *name.symbol);
+ }
}
void DoForallChecker::Leave(const parser::StatVariable &statVariable) {
diff --git a/flang/test/Semantics/resolve40.f90 b/flang/test/Semantics/resolve40.f90
index a91507aa62282..81bb5f989ec48 100644
--- a/flang/test/Semantics/resolve40.f90
+++ b/flang/test/Semantics/resolve40.f90
@@ -96,3 +96,10 @@ subroutine s12(x)
!BECAUSE: 'x' is an INTENT(IN) dummy argument
read(*,nml=nl)
end
+
+subroutine s13()
+ implicit none
+ !ERROR: No explicit type declared for 'i'
+ !ERROR: No explicit type declared for 'i'
+ print *, (i, i = 1, 2)
+end
More information about the flang-commits
mailing list