[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 20:28:50 PST 2024


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

>From 2f5e255c59405555e29b350ff742c3bbbb71badf 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 f60cdbb690e7c..0739c5d4e1866 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -922,8 +922,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 431d701a247b3721ddef8ada603cee0ddfc70025 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 0739c5d4e1866..d8271b1f14635 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -924,8 +924,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=*/{}};
     }
@@ -933,7 +932,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