Skip to content

Commit

Permalink
[flang] Don't implicitly host-associate unknown EQUIVALENCE designators
Browse files Browse the repository at this point in the history
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.

Differential Revision: https://reviews.llvm.org/D159030
  • Loading branch information
klausler committed Aug 29, 2023
1 parent f0731d5 commit 4d32f9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7277,7 +7277,7 @@ const parser::Name *DeclarationVisitor::ResolveName(const parser::Name &name) {
// 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) {
Expand Down
12 changes: 11 additions & 1 deletion flang/test/Semantics/offsets03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subroutine mc !CHECK: Subprogram scope: mc size=12 alignment=1

! 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:
Expand Down Expand Up @@ -65,3 +65,13 @@ module me
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

0 comments on commit 4d32f9a

Please sign in to comment.