Skip to content

Commit

Permalink
[flang] Create HostAssocDetails symbols when needed for mis-parsed Ar…
Browse files Browse the repository at this point in the history
…rayRef

Name resolution is always creating symbols with HostAssocDetails
for host variable names inside internal procedures. This helps lowering
identifying and dealing with such variables inside internal procedures.

However, the case where the variable appears in an ArrayRef mis-parsed
as a FunctionRef goes through a different name resolution path that did
not create such HostAssocDetails when needed. Pointer assignment RHS
are also skipping this path.

Add the logic to create HostAssocDetails for host symbols inisde internal
procedures that appear in mis-parsed ArrayRef or in pointer assignment RHS.

Differential Revision: https://reviews.llvm.org/D105464
  • Loading branch information
jeanPerier committed Jul 7, 2021
1 parent 0c1a773 commit c2d4d6a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
26 changes: 19 additions & 7 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ class DeclarationVisitor : public ArraySpecVisitor,
const parser::Name *ResolveName(const parser::Name &);
bool PassesSharedLocalityChecks(const parser::Name &name, Symbol &symbol);
Symbol *NoteInterfaceName(const parser::Name &);
bool IsUplevelReference(const Symbol &);

private:
// The attribute corresponding to the statement containing an ObjectDecl
Expand Down Expand Up @@ -971,7 +972,6 @@ class DeclarationVisitor : public ArraySpecVisitor,
void AddSaveName(std::set<SourceName> &, const SourceName &);
void SetSaveAttr(Symbol &);
bool HandleUnrestrictedSpecificIntrinsicFunction(const parser::Name &);
bool IsUplevelReference(const Symbol &);
const parser::Name *FindComponent(const parser::Name *, const parser::Name &);
void Initialization(const parser::Name &, const parser::Initialization &,
bool inComponentDecl);
Expand Down Expand Up @@ -6186,13 +6186,19 @@ void ResolveNamesVisitor::HandleProcedureName(
symbol->attrs().test(Attr::ABSTRACT)) {
Say(name, "Abstract interface '%s' may not be called"_err_en_US);
} else if (IsProcedure(*symbol) || symbol->has<DerivedTypeDetails>() ||
symbol->has<ObjectEntityDetails>() ||
symbol->has<AssocEntityDetails>()) {
// Symbols with DerivedTypeDetails, ObjectEntityDetails and
// AssocEntityDetails are accepted here as procedure-designators because
// this means the related FunctionReference are mis-parsed structure
// constructors or array references that will be fixed later when
// analyzing expressions.
// Symbols with DerivedTypeDetails and AssocEntityDetails are accepted
// here as procedure-designators because this means the related
// FunctionReference are mis-parsed structure constructors or array
// references that will be fixed later when analyzing expressions.
} else if (symbol->has<ObjectEntityDetails>()) {
// Symbols with ObjectEntityDetails are also accepted because this can be
// a mis-parsed array references that will be fixed later. Ensure that if
// this is a symbol from a host procedure, a symbol with HostAssocDetails
// is created for the current scope.
if (IsUplevelReference(*symbol)) {
MakeHostAssocSymbol(name, *symbol);
}
} else if (symbol->test(Symbol::Flag::Implicit)) {
Say(name,
"Use of '%s' as a procedure conflicts with its implicit definition"_err_en_US);
Expand Down Expand Up @@ -6589,6 +6595,12 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
// Resolve unrestricted specific intrinsic procedures as in "p => cos".
if (const parser::Name * name{parser::Unwrap<parser::Name>(expr)}) {
if (NameIsKnownOrIntrinsic(*name)) {
// If the name is known because it is an object entity from a host
// procedure, create a host associated symbol.
if (Symbol * symbol{name->symbol}; symbol &&
symbol->has<ObjectEntityDetails>() && IsUplevelReference(*symbol)) {
MakeHostAssocSymbol(*name, *symbol);
}
return false;
}
}
Expand Down
31 changes: 31 additions & 0 deletions flang/test/Semantics/symbol03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,34 @@ subroutine s2
end subroutine
end subroutine
end program

!DEF: /s (Subroutine) Subprogram
subroutine s
!DEF: /s/x ObjectEntity REAL(4)
real x(100, 100)
!DEF: /s/s1 (Subroutine) Subprogram
call s1
contains
!REF: /s/s1
subroutine s1
!DEF: /s/s1/x HostAssoc REAL(4)
print *, x(10, 10)
end subroutine
end subroutine

!DEF: /sb (Subroutine) Subprogram
subroutine sb
!DEF: /sb/x TARGET ObjectEntity REAL(4)
real, target :: x
!DEF: /sb/s1 (Subroutine) Subprogram
call s1
contains
!REF: /sb/s1
subroutine s1
!DEF: /sb/s1/p POINTER ObjectEntity REAL(4)
real, pointer :: p
!REF: /sb/s1/p
!DEF: /sb/s1/x TARGET HostAssoc REAL(4)
p => x
end subroutine
end subroutine

0 comments on commit c2d4d6a

Please sign in to comment.