[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
This commit is contained in:
Eugene Epshteyn
2025-03-04 20:41:01 -05:00
committed by GitHub
parent 95c64b7ee6
commit ab6cc6b7b3
3 changed files with 7 additions and 12 deletions

View File

@@ -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);

View File

@@ -69,8 +69,8 @@ end
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

View File

@@ -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/