[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 6 10:25:52 PST 2023


================
@@ -870,6 +878,22 @@ 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/dummy arguments.
+  // It could have a combination of
+  //     acutal             dummy
+  // 2.  procedure pointer  procedure pointer
+  // 3.  procedure pointer  procedure
+  // 4.  procedure          procedure pointer
+  if (hlfir::isBoxProcAddressType(actual.getType()) ||
+      hlfir::isBoxProcAddressType(dummyType)) {
+    if (actual.getType() != dummyType &&
+        hlfir::isBoxProcAddressType(actual.getType())) {
+      auto baseAddr{actual.getFirBase()};
+      actual = hlfir::Entity{builder.create<fir::LoadOp>(loc, baseAddr)};
+    }
+    return PreparedDummyArgument{actual, /*cleanups=*/{}};
+  }
----------------
jeanPerier wrote:

I think the procedure actual to procedure pointer actual may not be covered here (I would expect  a temp + store created to cover this case).

Fortran::evaluate::NullPointer may also need custom handling here to handle passing NULL to an intent(in) procedure pointer (like with the PassBy::MutableBox).

I think this custom handling would deserve to be in its own spot and it would be simpler if:
- PassBy::BoxProcRef was added and was set in CallInterface.cpp when the dummy is a procedure pointer.
- hlfir::derefPointersAndAllocatables was updated to deref fir.ref<fir.boxproc> (which would lead to genExprAddr to automatically deference the procedure). That way, no change would be need to support passing procedure pointers to procedure dummies.

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


More information about the flang-commits mailing list