Skip to content

Commit

Permalink
[flang] Fix result type of "procedure(abs) :: f"
Browse files Browse the repository at this point in the history
Name resolution was properly probing the table of unrestricted
specific intrinsics to find "abs", but failing to capture the
result type and save it in the created symbol table entry.

Differential Revision: https://reviews.llvm.org/D120749
  • Loading branch information
klausler committed Mar 2, 2022
1 parent 859d4a1 commit 1e082a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions flang/lib/Semantics/resolve-names.cpp
Expand Up @@ -5124,10 +5124,24 @@ bool DeclarationVisitor::HandleUnrestrictedSpecificIntrinsicFunction(
if (auto interface{context().intrinsics().IsSpecificIntrinsicFunction(
name.source.ToString())}) {
// Unrestricted specific intrinsic function names (e.g., "cos")
// are acceptable as procedure interfaces.
// are acceptable as procedure interfaces. The presence of the
// INTRINSIC flag will cause this symbol to have a complete interface
// recreated for it later on demand, but capturing its result type here
// will make GetType() return a correct result without having to
// probe the intrinsics table again.
Symbol &symbol{
MakeSymbol(InclusiveScope(), name.source, Attrs{Attr::INTRINSIC})};
symbol.set_details(ProcEntityDetails{});
CHECK(interface->functionResult.has_value());
evaluate::DynamicType dyType{
DEREF(interface->functionResult->GetTypeAndShape()).type()};
CHECK(common::IsNumericTypeCategory(dyType.category()));
const DeclTypeSpec &typeSpec{
MakeNumericType(dyType.category(), dyType.kind())};
ProcEntityDetails details;
ProcInterface procInterface;
procInterface.set_type(typeSpec);
details.set_interface(procInterface);
symbol.set_details(std::move(details));
symbol.set(Symbol::Flag::Function);
if (interface->IsElemental()) {
symbol.attrs().set(Attr::ELEMENTAL);
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/procinterface01.f90
Expand Up @@ -53,13 +53,13 @@ end function tan
!DEF: /module1/derived1/p5 NOPASS, POINTER (Function) ProcEntity COMPLEX(4)
!DEF: /module1/nested4 PUBLIC (Function) Subprogram COMPLEX(4)
procedure(complex), pointer, nopass :: p5 => nested4
!DEF: /module1/sin ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity
!DEF: /module1/derived1/p6 NOPASS, POINTER (Function) ProcEntity
!DEF: /module1/sin ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity REAL(4)
!DEF: /module1/derived1/p6 NOPASS, POINTER (Function) ProcEntity REAL(4)
!REF: /module1/nested1
procedure(sin), pointer, nopass :: p6 => nested1
!REF: /module1/sin
!DEF: /module1/derived1/p7 NOPASS, POINTER (Function) ProcEntity
!DEF: /module1/cos ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity
!DEF: /module1/derived1/p7 NOPASS, POINTER (Function) ProcEntity REAL(4)
!DEF: /module1/cos ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity REAL(4)
procedure(sin), pointer, nopass :: p7 => cos
!REF: /module1/tan
!DEF: /module1/derived1/p8 NOPASS, POINTER (Function) ProcEntity CHARACTER(1_4,1)
Expand Down

0 comments on commit 1e082a4

Please sign in to comment.