[flang-commits] [flang] [Flang] Avoid crash on invalid EQUIVALENCE objects (PR #215979)

via flang-commits flang-commits at lists.llvm.org
Thu Aug 13 05:57:08 PDT 2026


https://github.com/keepyixiao updated https://github.com/llvm/llvm-project/pull/215979

>From c19bbb51e00dc263f5991f5f9cab3a9a227cecb6 Mon Sep 17 00:00:00 2001
From: yixiao <yixiao at hygon.cn>
Date: Thu, 13 Aug 2026 15:51:14 +0800
Subject: [PATCH] [Flang] Avoid crash on invalid EQUIVALENCE objects

An invalid EQUIVALENCE statement may introduce a symbol that is not a
data object into later offset computation. ComputeOffsetsHelper assumes
such symbols have ObjectEntityDetails when assigning COMMON block
information, which can cause a crash after a semantic error.

Check for ObjectEntityDetails before accessing object-specific
information to keep error recovery paths safe.

Test coverage
- Add a regression test for using a subroutine name as an EQUIVALENCE object.

Tests:
- llvm-lit -v flang/test/Semantics/equivalence-non-data-object.f90
---
 flang/lib/Semantics/compute-offsets.cpp              | 4 +++-
 flang/test/Semantics/equivalence-non-data-object.f90 | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/equivalence-non-data-object.f90

diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp
index 3a355f040b865..f72bc844e89b6 100644
--- a/flang/lib/Semantics/compute-offsets.cpp
+++ b/flang/lib/Semantics/compute-offsets.cpp
@@ -212,7 +212,9 @@ void ComputeOffsetsHelper::Compute(Scope &scope) {
   for (auto &[symbol, dep] : dependents_) {
     symbol->set_offset(dep.symbol->offset() + dep.offset);
     if (const auto *block{FindCommonBlockContaining(*dep.symbol)}) {
-      symbol->get<ObjectEntityDetails>().set_commonBlock(*block);
+      if (auto *object{symbol->detailsIf<ObjectEntityDetails>()}) {
+        object->set_commonBlock(*block);
+      }
     }
   }
 }
diff --git a/flang/test/Semantics/equivalence-non-data-object.f90 b/flang/test/Semantics/equivalence-non-data-object.f90
new file mode 100644
index 0000000000000..20e6762c03581
--- /dev/null
+++ b/flang/test/Semantics/equivalence-non-data-object.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+subroutine test3()
+  common /blk/ k1
+  ! ERROR: 'test3' in equivalence set is not a data object
+  equivalence(i1, TEST3, k1) 
+end subroutine test3



More information about the flang-commits mailing list