Skip to content

Commit a56e870

Browse files
eugeneepshteynjph-13
authored andcommitted
[flang] Allow nested scopes for implied DO loops with DATA statements (llvm#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
1 parent 241e692 commit a56e870

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7490,15 +7490,10 @@ bool ConstructVisitor::Pre(const parser::DataImpliedDo &x) {
74907490
Walk(bounds.upper);
74917491
Walk(bounds.step);
74927492
EndCheckOnIndexUseInOwnBounds(restore);
7493-
bool pushScope{currScope().kind() != Scope::Kind::ImpliedDos};
7494-
if (pushScope) {
7495-
PushScope(Scope::Kind::ImpliedDos, nullptr);
7496-
}
7493+
PushScope(Scope::Kind::ImpliedDos, nullptr);
74977494
DeclareStatementEntity(bounds.name, type);
74987495
Walk(objects);
7499-
if (pushScope) {
7500-
PopScope();
7501-
}
7496+
PopScope();
75027497
return false;
75037498
}
75047499

@@ -7539,9 +7534,9 @@ bool ConstructVisitor::Pre(const parser::DataStmtObject &x) {
75397534
}
75407535
},
75417536
[&](const parser::DataImpliedDo &y) {
7542-
PushScope(Scope::Kind::ImpliedDos, nullptr);
7537+
// Don't push scope here, since it's done when visiting
7538+
// DataImpliedDo.
75437539
Walk(y);
7544-
PopScope();
75457540
},
75467541
},
75477542
x.u);

flang/test/Semantics/resolve40.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ subroutine s8
6969

7070
subroutine s9
7171
real :: x(2,2)
72-
!ERROR: 'i' is already declared in this scoping unit
73-
data ((x(i,i),i=1,2),i=1,2)/4*0.0/
72+
! Nested implied DO loops have their own scope
73+
data ((x(i,j),j=1,2),(x(i,j),j=1,2),i=1,2)/8*0.0/
7474
end
7575

7676
module m10

flang/test/Semantics/symbol09.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ subroutine s3
5151
real, dimension(n,n) :: x
5252
!REF: /s3/x
5353
!DEF: /s3/ImpliedDos1/k (Implicit) ObjectEntity INTEGER(4)
54-
!DEF: /s3/ImpliedDos1/j ObjectEntity INTEGER(8)
54+
!DEF: /s3/ImpliedDos1/ImpliedDos1/j ObjectEntity INTEGER(8)
5555
!REF: /s3/n
5656
!REF: /s3/n2
5757
data ((x(k,j),integer(kind=8)::j=1,n),k=1,n)/n2*3.0/

0 commit comments

Comments
 (0)