Skip to content

Commit 21d006c

Browse files
[flang] Support kind/index lookup inside of EQUIVALENCE (#170056)
Turn off "in EQUIVALENCE" check for processing of array subscripts, since subscripts themselves are not part of the EQUIVALENCE. Fixes #169590
1 parent 00c8e61 commit 21d006c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ class ResolveNamesVisitor : public virtual ScopeHandler,
21532153
void Post(const parser::AssignedGotoStmt &);
21542154
void Post(const parser::CompilerDirective &);
21552155

2156+
bool Pre(const parser::SectionSubscript &);
2157+
21562158
// These nodes should never be reached: they are handled in ProgramUnit
21572159
bool Pre(const parser::MainProgram &) {
21582160
llvm_unreachable("This node is handled in ProgramUnit");
@@ -10218,6 +10220,14 @@ template <typename A> std::set<SourceName> GetUses(const A &x) {
1021810220
return uses;
1021910221
}
1022010222

10223+
bool ResolveNamesVisitor::Pre(const parser::SectionSubscript &x) {
10224+
// Turn off "in EQUIVALENCE" check for array indexing, because
10225+
// the indices themselves are not part of the EQUIVALENCE.
10226+
auto restorer{common::ScopedSet(inEquivalenceStmt_, false)};
10227+
Walk(x.u);
10228+
return false;
10229+
}
10230+
1022110231
bool ResolveNamesVisitor::Pre(const parser::Program &x) {
1022210232
if (Scope * hermetic{context().currentHermeticModuleFileScope()}) {
1022310233
// Processing either the dependent modules or first module of a
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
module equiv_kind_m
3+
implicit none
4+
integer, parameter :: knd = kind(42)
5+
integer, parameter :: dim_2 = 1_knd
6+
integer, parameter :: n = 3_knd
7+
integer, parameter :: i_start = 1_knd
8+
contains
9+
subroutine test()
10+
integer(knd) :: a(n),b(n,n)
11+
character(len=5) :: small_ch
12+
character(len=20) :: large_ch
13+
14+
equivalence (a(1_knd),b(1_knd,dim_2))
15+
!CHECK: EQUIVALENCE (a(1_4), b(1_4,1_4))
16+
equivalence (small_ch, large_ch(i_start:5_knd))
17+
!CHECK: EQUIVALENCE (small_ch, large_ch(1_4:5_4))
18+
end subroutine test
19+
end module equiv_kind_m

0 commit comments

Comments
 (0)