Skip to content

Commit 1e082a4

Browse files
committed
[flang] Fix result type of "procedure(abs) :: f"
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
1 parent 859d4a1 commit 1e082a4

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,10 +5124,24 @@ bool DeclarationVisitor::HandleUnrestrictedSpecificIntrinsicFunction(
51245124
if (auto interface{context().intrinsics().IsSpecificIntrinsicFunction(
51255125
name.source.ToString())}) {
51265126
// Unrestricted specific intrinsic function names (e.g., "cos")
5127-
// are acceptable as procedure interfaces.
5127+
// are acceptable as procedure interfaces. The presence of the
5128+
// INTRINSIC flag will cause this symbol to have a complete interface
5129+
// recreated for it later on demand, but capturing its result type here
5130+
// will make GetType() return a correct result without having to
5131+
// probe the intrinsics table again.
51285132
Symbol &symbol{
51295133
MakeSymbol(InclusiveScope(), name.source, Attrs{Attr::INTRINSIC})};
5130-
symbol.set_details(ProcEntityDetails{});
5134+
CHECK(interface->functionResult.has_value());
5135+
evaluate::DynamicType dyType{
5136+
DEREF(interface->functionResult->GetTypeAndShape()).type()};
5137+
CHECK(common::IsNumericTypeCategory(dyType.category()));
5138+
const DeclTypeSpec &typeSpec{
5139+
MakeNumericType(dyType.category(), dyType.kind())};
5140+
ProcEntityDetails details;
5141+
ProcInterface procInterface;
5142+
procInterface.set_type(typeSpec);
5143+
details.set_interface(procInterface);
5144+
symbol.set_details(std::move(details));
51315145
symbol.set(Symbol::Flag::Function);
51325146
if (interface->IsElemental()) {
51335147
symbol.attrs().set(Attr::ELEMENTAL);

flang/test/Semantics/procinterface01.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ end function tan
5353
!DEF: /module1/derived1/p5 NOPASS, POINTER (Function) ProcEntity COMPLEX(4)
5454
!DEF: /module1/nested4 PUBLIC (Function) Subprogram COMPLEX(4)
5555
procedure(complex), pointer, nopass :: p5 => nested4
56-
!DEF: /module1/sin ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity
57-
!DEF: /module1/derived1/p6 NOPASS, POINTER (Function) ProcEntity
56+
!DEF: /module1/sin ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity REAL(4)
57+
!DEF: /module1/derived1/p6 NOPASS, POINTER (Function) ProcEntity REAL(4)
5858
!REF: /module1/nested1
5959
procedure(sin), pointer, nopass :: p6 => nested1
6060
!REF: /module1/sin
61-
!DEF: /module1/derived1/p7 NOPASS, POINTER (Function) ProcEntity
62-
!DEF: /module1/cos ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity
61+
!DEF: /module1/derived1/p7 NOPASS, POINTER (Function) ProcEntity REAL(4)
62+
!DEF: /module1/cos ELEMENTAL, INTRINSIC, PUBLIC, PURE (Function) ProcEntity REAL(4)
6363
procedure(sin), pointer, nopass :: p7 => cos
6464
!REF: /module1/tan
6565
!DEF: /module1/derived1/p8 NOPASS, POINTER (Function) ProcEntity CHARACTER(1_4,1)

0 commit comments

Comments
 (0)