[flang-commits] [PATCH] D120749: [flang] Fix result type of "procedure(abs) :: f"
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Mar 1 10:00:57 PST 2022
klausler created this revision.
klausler added a reviewer: schweitz.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D120749
Files:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/procinterface01.f90
Index: flang/test/Semantics/procinterface01.f90
===================================================================
--- flang/test/Semantics/procinterface01.f90
+++ flang/test/Semantics/procinterface01.f90
@@ -53,13 +53,13 @@
!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)
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -5124,10 +5124,24 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120749.412149.patch
Type: text/x-patch
Size: 2859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220301/59034b2f/attachment.bin>
More information about the flang-commits
mailing list