[flang-commits] [flang] [flang] Support kind/index lookup inside of EQUIVALENCE (PR #170056)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 2 12:47:11 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Eugene Epshteyn (eugeneepshteyn)
<details>
<summary>Changes</summary>
Turn off "in EQUIVALENCE" check for processing of array subscripts, since subscripts themselves are not part of the EQUIVALENCE.
Fixes #<!-- -->169590
---
Full diff: https://github.com/llvm/llvm-project/pull/170056.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+10)
- (added) flang/test/Semantics/equiv-kind.f90 (+19)
``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 2a487a6d39d51..4c8bffdef7d41 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2153,6 +2153,8 @@ class ResolveNamesVisitor : public virtual ScopeHandler,
void Post(const parser::AssignedGotoStmt &);
void Post(const parser::CompilerDirective &);
+ bool Pre(const parser::SectionSubscript &);
+
// These nodes should never be reached: they are handled in ProgramUnit
bool Pre(const parser::MainProgram &) {
llvm_unreachable("This node is handled in ProgramUnit");
@@ -10217,6 +10219,14 @@ template <typename A> std::set<SourceName> GetUses(const A &x) {
return uses;
}
+bool ResolveNamesVisitor::Pre(const parser::SectionSubscript &x) {
+ // Turn off "in EQUIVALENCE" check for array indexing, because
+ // the indices themselves are not part of the EQUIVALENCE.
+ auto restorer{common::ScopedSet(inEquivalenceStmt_, false)};
+ Walk(x.u);
+ return false;
+}
+
bool ResolveNamesVisitor::Pre(const parser::Program &x) {
if (Scope * hermetic{context().currentHermeticModuleFileScope()}) {
// Processing either the dependent modules or first module of a
diff --git a/flang/test/Semantics/equiv-kind.f90 b/flang/test/Semantics/equiv-kind.f90
new file mode 100644
index 0000000000000..d54fe62ee77db
--- /dev/null
+++ b/flang/test/Semantics/equiv-kind.f90
@@ -0,0 +1,19 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+module equiv_kind_m
+ implicit none
+ integer, parameter :: knd = kind(42)
+ integer, parameter :: dim_2 = 1_knd
+ integer, parameter :: n = 3_knd
+ integer, parameter :: i_start = 1_knd
+contains
+subroutine test()
+ integer(knd) :: a(n),b(n,n)
+ character(len=5) :: small_ch
+ character(len=20) :: large_ch
+
+ equivalence (a(1_knd),b(1_knd,dim_2))
+ !CHECK: EQUIVALENCE (a(1_4), b(1_4,1_4))
+ equivalence (small_ch, large_ch(i_start:5_knd))
+ !CHECK: EQUIVALENCE (small_ch, large_ch(1_4:5_4))
+end subroutine test
+end module equiv_kind_m
``````````
</details>
https://github.com/llvm/llvm-project/pull/170056
More information about the flang-commits
mailing list