[flang-commits] [flang] [Flang] Support passing a function that returns procedure pointer as actual corresponding to a procedure dummy. (PR #80891)

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Wed Feb 7 09:45:15 PST 2024


https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/80891

>From ec7bb8c0cbdaaf692dd51ce36ab4c1e663c1ea09 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Tue, 6 Feb 2024 13:27:25 -0500
Subject: [PATCH 1/2] [Flag] Support passing a function that returns procedure
 pointer as actual corresponding to a procedure dummy.

---
 flang/lib/Lower/ConvertCall.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index bb8fd2e945f437..bd6bd811179669 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -915,8 +915,10 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
   // Handle procedure arguments (procedure pointers should go through
   // prepareProcedurePointerActualArgument).
   if (hlfir::isFortranProcedureValue(dummyType)) {
-    // Procedure pointer actual to procedure dummy.
-    if (actual.isProcedurePointer()) {
+    // Procedure pointer or function returns procedure pointer actual to
+    // procedure dummy.
+    if (actual.isProcedurePointer() ||
+        actual.getType().isa<fir::BoxProcType>()) {
       actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
       return PreparedDummyArgument{actual, /*cleanups=*/{}};
     }

>From 5b02933494521bdad4d662b44c7ba92ba168a571 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Wed, 7 Feb 2024 12:44:57 -0500
Subject: [PATCH 2/2] [Flang] Address review comments.

---
 flang/lib/Lower/ConvertCall.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index bd6bd811179669..e7da56d8ef6eba 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -917,8 +917,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
   if (hlfir::isFortranProcedureValue(dummyType)) {
     // Procedure pointer or function returns procedure pointer actual to
     // procedure dummy.
-    if (actual.isProcedurePointer() ||
-        actual.getType().isa<fir::BoxProcType>()) {
+    if (actual.isProcedurePointer()) {
       actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
       return PreparedDummyArgument{actual, /*cleanups=*/{}};
     }
@@ -926,7 +925,11 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
     assert(actual.isProcedure());
     // Do nothing if this is a procedure argument. It is already a
     // fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
-    if (actual.getType() != dummyType)
+    if (!actual.getType().isa<fir::BoxProcType>() &&
+        actual.getType() != dummyType)
+      // The actual argument may be a procedure that returns character (a
+      // fir.tuple<fir.boxproc, len>) while the dummy is not. Extract the tuple
+      // in that case.
       actual = fixProcedureDummyMismatch(loc, builder, actual, dummyType);
     return PreparedDummyArgument{actual, /*cleanups=*/{}};
   }



More information about the flang-commits mailing list