[flang-commits] [PATCH] D159030: [flang] Don't implicitly host-associate unknown EQUIVALENCE designators

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Aug 28 15:48:32 PDT 2023


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

When resolving names in a specification part, unknown names that appear
in a specification expression before any local declaration are assumed
to be implicitly declared objects in the host scope.  Objects in
EQUIVALENCE sets are not part of specification expressions, so ensure
that they do not receive this treatment; besides being wrong and
unimplementable, it will lead to a later crash during offset assignment.


https://reviews.llvm.org/D159030

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/offsets03.f90


Index: flang/test/Semantics/offsets03.f90
===================================================================
--- flang/test/Semantics/offsets03.f90
+++ flang/test/Semantics/offsets03.f90
@@ -29,7 +29,7 @@
 
 ! Common block: objects are in order from COMMON statement and not part of module
 module md                   !CHECK: Module scope: md size=1 alignment=1
-  integer(1) :: i 
+  integer(1) :: i
   integer(2) :: d1          !CHECK: d1, PUBLIC size=2 offset=8:
   integer(4) :: d2          !CHECK: d2, PUBLIC size=4 offset=4:
   integer(1) :: d3          !CHECK: d3, PUBLIC size=1 offset=0:
@@ -65,3 +65,13 @@
   equivalence(a1,a3(1)),(a2,a3(2))
   common /common8/ a1, a2   ! CHECK: common8 size=8 offset=0: CommonBlockDetails alignment=4:
 end
+
+! Ensure EQUIVALENCE of undeclared names in internal subprogram doesn't
+! attempt to host-associate
+subroutine host1
+ contains
+  subroutine internal
+    common /b/ x(4)  ! CHECK: x (Implicit) size=16 offset=0: ObjectEntity type: REAL(4) shape: 1_8:4_8
+    equivalence(x,y) ! CHECK: y (Implicit) size=4 offset=0: ObjectEntity type: REAL(4)
+  end
+end
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -7282,7 +7282,7 @@
 // be wrong we report an error later in CheckDeclarations().
 bool DeclarationVisitor::CheckForHostAssociatedImplicit(
     const parser::Name &name) {
-  if (!inSpecificationPart_) {
+  if (!inSpecificationPart_ || inEquivalenceStmt_) {
     return false;
   }
   if (name.symbol) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159030.554079.patch
Type: text/x-patch
Size: 1617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230828/d57b03cf/attachment-0001.bin>


More information about the flang-commits mailing list