[PATCH] D91560: [flang] Duplicate names for ac-implied-do variables erroneously cause errors
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 16 12:08:43 PST 2020
PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld requested review of this revision.
According to section 19.4, paragraph 5, the scope of an ac-implied-do variable
is the enclosing ac-implied-do. But we were not creating new scopes upon
entry to an ac-implied-do. This was causing error messages to be erroneously
emitted.
I fixed, the code, added a test to array-constr-values.f90, and corrected the
test symbol05.f90.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91560
Files:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/array-constr-values.f90
flang/test/Semantics/symbol05.f90
Index: flang/test/Semantics/symbol05.f90
===================================================================
--- flang/test/Semantics/symbol05.f90
+++ flang/test/Semantics/symbol05.f90
@@ -48,10 +48,10 @@
!DEF: /s3/Block1/t DerivedType
type :: t
!DEF: /s3/Block1/t/x ObjectEntity REAL(4)
- !DEF: /s3/Block1/t/ImpliedDos1/i (Implicit) ObjectEntity INTEGER(4)
+ !DEF: /s3/Block1/t/ImpliedDos1/ImpliedDos1/i (Implicit) ObjectEntity INTEGER(4)
real :: x(10) = [(i, i=1,10)]
!DEF: /s3/Block1/t/y ObjectEntity REAL(4)
- !DEF: /s3/Block1/t/ImpliedDos2/j ObjectEntity INTEGER(8)
+ !DEF: /s3/Block1/t/ImpliedDos2/ImpliedDos1/j ObjectEntity INTEGER(8)
real :: y(10) = [(j, j=1,10)]
end type
end block
Index: flang/test/Semantics/array-constr-values.f90
===================================================================
--- flang/test/Semantics/array-constr-values.f90
+++ flang/test/Semantics/array-constr-values.f90
@@ -55,9 +55,14 @@
real, dimension(10), parameter :: good1 = [(99.9, i = 1, 10)]
real, dimension(100), parameter :: good2 = [((88.8, i = 1, 10), j = 1, 10)]
!ERROR: Implied DO index is active in surrounding implied DO loop and may not have the same name
- !ERROR: 'i' is already declared in this scoping unit
real, dimension(100), parameter :: bad = [((88.8, i = 1, 10), i = 1, 10)]
!ERROR: The stride of an implied DO loop must not be zero
integer, parameter :: bad2(*) = [(j, j=1,1,0)]
end subroutine checkC7115
+subroutine checkOkDuplicates
+ real :: realArray(21) = &
+ [ ((1.0, iDuplicate = 1,j), &
+ (0.0, iDuplicate = j,3 ), &
+ j = 1,5 ) ]
+end subroutine
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -4995,14 +4995,18 @@
return false;
}
+// Section 19.4, paragraph 5 says that each ac-do-variable has the scope of the
+// enclocing ac-impled-do
bool ConstructVisitor::Pre(const parser::AcImpliedDo &x) {
auto &values{std::get<std::list<parser::AcValue>>(x.t)};
auto &control{std::get<parser::AcImpliedDoControl>(x.t)};
auto &type{std::get<std::optional<parser::IntegerTypeSpec>>(control.t)};
auto &bounds{std::get<parser::AcImpliedDoControl::Bounds>(control.t)};
+ PushScope(Scope::Kind::ImpliedDos, nullptr);
DeclareStatementEntity(bounds.name.thing.thing, type);
Walk(bounds);
Walk(values);
+ PopScope();
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91560.305572.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/49e4d02f/attachment.bin>
More information about the llvm-commits
mailing list