[flang-commits] [flang] [Flang] Add partial support for lowering procedure pointer assignment. (PR #70461)

via flang-commits flang-commits at lists.llvm.org
Mon Nov 13 02:17:45 PST 2023


================
@@ -870,9 +874,28 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
   // element if this is an array in an elemental call.
   hlfir::Entity actual = preparedActual.getActual(loc, builder);
 
+  // Handles the procedure pointer actual arguments.
+  if (actual.isProcedurePointer()) {
+    if (hlfir::isBoxProcAddressType(dummyType))
+      // Procedure pointer actual to procedure pointer dummy.
+      return PreparedDummyArgument{actual, /*cleanups=*/{}};
+    if (hlfir::isFortranProcedureValue(dummyType)) {
+      // Procedure pointer actual to procedure dummy.
+      actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
+      return PreparedDummyArgument{actual, /*cleanups=*/{}};
+    }
+  }
+
   // Do nothing if this is a procedure argument. It is already a
   // fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
   if (actual.isProcedure()) {
+    if (hlfir::isBoxProcAddressType(dummyType)) {
+      // Procedure actual to procedure pointer dummy.
+      auto proc{fir::getBase(actual)};
----------------
jeanPerier wrote:

`fir::getBase` is not needed on hlfir::Entity, an hlfir::Entity is an mlir::Value (it inherits from it), so you can use actual.getType() directly.

Note that fir::getBase works but does a unnecessary merry-go round (implicitly creates a fir::ExtendedValue from the mlir::Value base of the hlfir::Entity, and does an std::variant visit to get the mlir::Value back).

https://github.com/llvm/llvm-project/pull/70461


More information about the flang-commits mailing list