[flang-commits] [flang] ab6cc6b - [flang] Allow nested scopes for implied DO loops with DATA statements (#129410)
via flang-commits
flang-commits at lists.llvm.org
Tue Mar 4 17:41:04 PST 2025
Author: Eugene Epshteyn
Date: 2025-03-04T20:41:01-05:00
New Revision: ab6cc6b7b3a3de5e6f5999601f0d40ab2b2819e2
URL: https://github.com/llvm/llvm-project/commit/ab6cc6b7b3a3de5e6f5999601f0d40ab2b2819e2
DIFF: https://github.com/llvm/llvm-project/commit/ab6cc6b7b3a3de5e6f5999601f0d40ab2b2819e2.diff
LOG: [flang] Allow nested scopes for implied DO loops with DATA statements (#129410)
Previously, nested scopes for implied DO loops with DATA statements were
disallowed, which meant that the following code couldn't compile due to
re-use of `j` loop variable name:
DATA (a(i),(b(i,j),j=1,3),(c(i,j),j=1,3),i=0,4)/
This change allows nested scopes implied DO loops, which allows the code
above to compile.
Tests modified to in accordance with this change:
Semantics/resolve40.f90, Semantics/symbol09.f90
Added:
Modified:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/resolve40.f90
flang/test/Semantics/symbol09.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 02b91f15e7cf4..2a2daf1575a2b 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7490,15 +7490,10 @@ bool ConstructVisitor::Pre(const parser::DataImpliedDo &x) {
Walk(bounds.upper);
Walk(bounds.step);
EndCheckOnIndexUseInOwnBounds(restore);
- bool pushScope{currScope().kind() != Scope::Kind::ImpliedDos};
- if (pushScope) {
- PushScope(Scope::Kind::ImpliedDos, nullptr);
- }
+ PushScope(Scope::Kind::ImpliedDos, nullptr);
DeclareStatementEntity(bounds.name, type);
Walk(objects);
- if (pushScope) {
- PopScope();
- }
+ PopScope();
return false;
}
@@ -7539,9 +7534,9 @@ bool ConstructVisitor::Pre(const parser::DataStmtObject &x) {
}
},
[&](const parser::DataImpliedDo &y) {
- PushScope(Scope::Kind::ImpliedDos, nullptr);
+ // Don't push scope here, since it's done when visiting
+ // DataImpliedDo.
Walk(y);
- PopScope();
},
},
x.u);
diff --git a/flang/test/Semantics/resolve40.f90 b/flang/test/Semantics/resolve40.f90
index b3384a91097d7..a91507aa62282 100644
--- a/flang/test/Semantics/resolve40.f90
+++ b/flang/test/Semantics/resolve40.f90
@@ -69,8 +69,8 @@ subroutine s8
subroutine s9
real :: x(2,2)
- !ERROR: 'i' is already declared in this scoping unit
- data ((x(i,i),i=1,2),i=1,2)/4*0.0/
+ ! Nested implied DO loops have their own scope
+ data ((x(i,j),j=1,2),(x(i,j),j=1,2),i=1,2)/8*0.0/
end
module m10
diff --git a/flang/test/Semantics/symbol09.f90 b/flang/test/Semantics/symbol09.f90
index 98cd1d954c3e7..0ed80b55b34d1 100644
--- a/flang/test/Semantics/symbol09.f90
+++ b/flang/test/Semantics/symbol09.f90
@@ -51,7 +51,7 @@ subroutine s3
real, dimension(n,n) :: x
!REF: /s3/x
!DEF: /s3/ImpliedDos1/k (Implicit) ObjectEntity INTEGER(4)
- !DEF: /s3/ImpliedDos1/j ObjectEntity INTEGER(8)
+ !DEF: /s3/ImpliedDos1/ImpliedDos1/j ObjectEntity INTEGER(8)
!REF: /s3/n
!REF: /s3/n2
data ((x(k,j),integer(kind=8)::j=1,n),k=1,n)/n2*3.0/
More information about the flang-commits
mailing list