diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -7277,7 +7277,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) { diff --git a/flang/test/Semantics/offsets03.f90 b/flang/test/Semantics/offsets03.f90 --- a/flang/test/Semantics/offsets03.f90 +++ b/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